Class: Mutations::Authentication::ResetPassword

Inherits:
GraphQL::Schema::Mutation
  • Object
show all
Includes:
Graphql::AccountLockHelper
Defined in:
app/graphql/mutations/authentication/reset_password.rb

Instance Method Summary collapse

Methods included from Graphql::AccountLockHelper

#account_locked?, #lockable?

Instance Method Details

#resolve(args) ⇒ Object



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
# File 'app/graphql/mutations/authentication/reset_password.rb', line 21

def resolve(args)
  if lockable?
    user = User.where(locked_at: nil).reset_password_by_token args
  else
    user = User.reset_password_by_token args
  end

  if user.errors.any?
    {
      success: false,
      errors: user.errors.messages.map { |field, messages|
        error_field = field == :reset_password_token ? :_error : field.to_s.camelize(:lower)

        {
          field: error_field,
          message: messages.first.capitalize,
          details: user.errors.details.dig(field)
        }
      }
    }
  else
    {
      errors: [],
      success: true
    }
  end
end