Commit 41fa8e2d authored by Sean Arnold's avatar Sean Arnold

Simplify rotation params handling

parent f20bb455
......@@ -38,22 +38,28 @@ module Mutations
end
def parsed_params(schedule, participants, args)
rotation_length = args.dig(:rotation_length, :length)
rotation_length_unit = args.dig(:rotation_length, :unit)
starts_at = parse_datetime(schedule, args[:starts_at])
ends_at = parse_datetime(schedule, args[:ends_at]) if args[:ends_at]
params = args.slice(:name)
active_period_start, active_period_end = active_period_times(args)
params[:participants] = find_participants(participants)
params[:starts_at] = parse_datetime(schedule, args[:starts_at]) if args[:starts_at]
params[:ends_at] = parse_datetime(schedule, args[:ends_at]) if args[:ends_at]
{
length: rotation_length,
length_unit: rotation_length_unit,
starts_at: starts_at,
ends_at: ends_at,
participants: find_participants(participants),
if args[:rotation_length]
params.merge!(
length: args.dig(:rotation_length, :length),
length_unit: args.dig(:rotation_length, :unit)
)
end
if args[:active_period].present?
active_period_start, active_period_end = active_period_times(args)
params.merge!(
active_period_start: active_period_start,
active_period_end: active_period_end
}
)
end
params
end
def parse_datetime(schedule, timestamp)
......
......@@ -57,7 +57,7 @@ module Mutations
schedule,
project,
current_user,
create_service_params(schedule, participants, args)
parsed_params(schedule, participants, args)
).execute
response(result)
......@@ -65,12 +65,6 @@ module Mutations
rescue ActiveRecord::RecordInvalid => e
raise Gitlab::Graphql::Errors::ArgumentError, e.message
end
private
def create_service_params(schedule, participants, args)
args.slice(:name).merge(parsed_params(schedule, participants, args))
end
end
end
end
......
......@@ -43,7 +43,7 @@ module Mutations
result = ::IncidentManagement::OncallRotations::EditService.new(
rotation,
current_user,
edit_service_params(rotation.schedule, args[:participants], args)
parsed_params(rotation.schedule, args[:participants], args)
).execute
response(result)
......@@ -51,24 +51,6 @@ module Mutations
private
def edit_service_params(schedule, participants, args)
parsed_service_params = parsed_params(schedule, participants, args)
args_to_update = parsed_service_params.slice(*args.keys)
if args[:rotation_length]
args_to_update[:length] = parsed_service_params[:length]
args_to_update[:length_unit] = parsed_service_params[:length_unit]
end
if args[:active_period]
args_to_update[:active_period_start] = parsed_service_params[:active_period_start]
args_to_update[:active_period_end] = parsed_service_params[:active_period_end]
end
args.slice(:name).merge(args_to_update)
end
def find_object(id:)
GitlabSchema.object_from_id(id, expected_type: ::IncidentManagement::OncallRotation)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment