Class: Mutations::Auth::UpdateAccount

Inherits:
GraphQL::Schema::Mutation
  • Object
show all
Defined in:
app/graphql/mutations/auth/update_account.rb

Instance Method Summary collapse

Instance Method Details

#resolve(args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/graphql/mutations/auth/update_account.rb', line 20

def resolve(args)
  user = context[:current_user]

  if user.blank?
    return {
      errors: [
        { field: :_error, message: I18n.t('devise.failure.unauthenticated') }
      ],
      success: false,
      user: nil
    }
  end

  user.update_with_password args

  if user.errors.any?
    {
      errors: user.errors.messages.map do |field, messages|
        { field: field.to_s.camelize(:lower), message: messages.first.capitalize }
      end,
      success: false,
      user: nil
    }
  else
    {
      errors: [],
      success: true,
      user: user
    }
  end
end