diff options
Diffstat (limited to 'app/graphql/mutations/timelogs')
-rw-r--r-- | app/graphql/mutations/timelogs/base.rb | 18 | ||||
-rw-r--r-- | app/graphql/mutations/timelogs/create.rb | 48 | ||||
-rw-r--r-- | app/graphql/mutations/timelogs/delete.rb | 13 |
3 files changed, 71 insertions, 8 deletions
diff --git a/app/graphql/mutations/timelogs/base.rb b/app/graphql/mutations/timelogs/base.rb new file mode 100644 index 00000000000..9859f0e7d79 --- /dev/null +++ b/app/graphql/mutations/timelogs/base.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Mutations + module Timelogs + class Base < Mutations::BaseMutation + field :timelog, + Types::TimelogType, + null: true, + description: 'Timelog.' + + private + + def response(result) + { timelog: result.payload[:timelog], errors: result.errors } + end + end + end +end diff --git a/app/graphql/mutations/timelogs/create.rb b/app/graphql/mutations/timelogs/create.rb new file mode 100644 index 00000000000..bab7508454e --- /dev/null +++ b/app/graphql/mutations/timelogs/create.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Mutations + module Timelogs + class Create < Base + graphql_name 'TimelogCreate' + + argument :time_spent, + GraphQL::Types::String, + required: true, + description: 'Amount of time spent.' + + argument :spent_at, + Types::DateType, + required: true, + description: 'When the time was spent.' + + argument :summary, + GraphQL::Types::String, + required: true, + description: 'Summary of time spent.' + + argument :issuable_id, + ::Types::GlobalIDType[::Issuable], + required: true, + description: 'Global ID of the issuable (Issue, WorkItem or MergeRequest).' + + authorize :create_timelog + + def resolve(issuable_id:, time_spent:, spent_at:, summary:, **args) + issuable = authorized_find!(id: issuable_id) + parsed_time_spent = Gitlab::TimeTrackingFormatter.parse(time_spent) + + result = ::Timelogs::CreateService.new( + issuable, parsed_time_spent, spent_at, summary, current_user + ).execute + + response(result) + end + + private + + def find_object(id:) + GitlabSchema.object_from_id(id, expected_type: [::Issue, ::WorkItem, ::MergeRequest]).sync + end + end + end +end diff --git a/app/graphql/mutations/timelogs/delete.rb b/app/graphql/mutations/timelogs/delete.rb index 8fd41c27b88..61588d839a7 100644 --- a/app/graphql/mutations/timelogs/delete.rb +++ b/app/graphql/mutations/timelogs/delete.rb @@ -2,14 +2,9 @@ module Mutations module Timelogs - class Delete < Mutations::BaseMutation + class Delete < Base graphql_name 'TimelogDelete' - field :timelog, - Types::TimelogType, - null: true, - description: 'Deleted timelog.' - argument :id, ::Types::GlobalIDType[::Timelog], required: true, @@ -22,11 +17,13 @@ module Mutations result = ::Timelogs::DeleteService.new(timelog, current_user).execute # Return the result payload, not the loaded timelog, so that it returns null in case of unauthorized access - { timelog: result.payload, errors: result.errors } + response(result) end + private + def find_object(id:) - GitlabSchema.find_by_gid(id) + GitlabSchema.object_from_id(id, expected_type: ::Timelog).sync end end end |