debian-mirror-gitlab/app/graphql/mutations/timelogs/create.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.5 KiB
Ruby
Raw Normal View History

2022-08-27 11:52:29 +05:30
# 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,
2023-03-04 22:38:38 +05:30
Types::TimeType,
2022-08-27 11:52:29 +05:30
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)
parsed_time_spent = Gitlab::TimeTrackingFormatter.parse(time_spent)
2023-03-04 22:38:38 +05:30
if parsed_time_spent.nil?
return { timelog: nil, errors: [_('Time spent must be formatted correctly. For example: 1h 30m.')] }
end
issuable = authorized_find!(id: issuable_id)
2022-08-27 11:52:29 +05:30
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