Class: Mutations::Auth::ResetPassword

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

Instance Method Summary collapse

Instance Method Details

#resolve(args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/graphql/mutations/auth/reset_password.rb', line 19

def resolve(args)
  user = User.where(locked_at: nil).reset_password_by_token args

  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