Class: Mutations::Timelogs::Create

Inherits:
Base
  • Object
show all
Defined in:
app/graphql/mutations/timelogs/create.rb

Constant Summary

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, authorization, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #ready?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #raise_resource_not_available_error!

Instance Method Details

#resolve(issuable_id:, time_spent:, spent_at:, summary:, **args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/graphql/mutations/timelogs/create.rb', line 30

def resolve(issuable_id:, time_spent:, spent_at:, summary:, **args)
  parsed_time_spent = Gitlab::TimeTrackingFormatter.parse(time_spent)
  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)

  result = ::Timelogs::CreateService.new(
    issuable, parsed_time_spent, spent_at, summary, current_user
  ).execute

  response(result)
end