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

Simplify rotation params handling

parent f20bb455
...@@ -38,22 +38,28 @@ module Mutations ...@@ -38,22 +38,28 @@ module Mutations
end end
def parsed_params(schedule, participants, args) def parsed_params(schedule, participants, args)
rotation_length = args.dig(:rotation_length, :length) params = args.slice(:name)
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]
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]
{ if args[:rotation_length]
length: rotation_length, params.merge!(
length_unit: rotation_length_unit, length: args.dig(:rotation_length, :length),
starts_at: starts_at, length_unit: args.dig(:rotation_length, :unit)
ends_at: ends_at, )
participants: find_participants(participants), 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_start: active_period_start,
active_period_end: active_period_end active_period_end: active_period_end
} )
end
params
end end
def parse_datetime(schedule, timestamp) def parse_datetime(schedule, timestamp)
......
...@@ -57,7 +57,7 @@ module Mutations ...@@ -57,7 +57,7 @@ module Mutations
schedule, schedule,
project, project,
current_user, current_user,
create_service_params(schedule, participants, args) parsed_params(schedule, participants, args)
).execute ).execute
response(result) response(result)
...@@ -65,12 +65,6 @@ module Mutations ...@@ -65,12 +65,6 @@ module Mutations
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
raise Gitlab::Graphql::Errors::ArgumentError, e.message raise Gitlab::Graphql::Errors::ArgumentError, e.message
end end
private
def create_service_params(schedule, participants, args)
args.slice(:name).merge(parsed_params(schedule, participants, args))
end
end end
end end
end end
......
...@@ -43,7 +43,7 @@ module Mutations ...@@ -43,7 +43,7 @@ module Mutations
result = ::IncidentManagement::OncallRotations::EditService.new( result = ::IncidentManagement::OncallRotations::EditService.new(
rotation, rotation,
current_user, current_user,
edit_service_params(rotation.schedule, args[:participants], args) parsed_params(rotation.schedule, args[:participants], args)
).execute ).execute
response(result) response(result)
...@@ -51,24 +51,6 @@ module Mutations ...@@ -51,24 +51,6 @@ module Mutations
private 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:) def find_object(id:)
GitlabSchema.object_from_id(id, expected_type: ::IncidentManagement::OncallRotation) GitlabSchema.object_from_id(id, expected_type: ::IncidentManagement::OncallRotation)
end 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