Class: Api::Dashboard::StaffsController
Instance Method Summary
collapse
#current_user, #identity_cache_memoization, #restaurants, #set_options
#append_info_to_payload
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
#my_response_cache
Instance Method Details
#forgot_password ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/api/dashboard/staffs_controller.rb', line 19
def forgot_password
if staff_param[:email].blank?
render json: { success: false, message: 'Email not present' },
status: :unprocessable_entity
return
end
staff = Staff.find_by(email: staff_param[:email])
service = StaffService::ForgotPassword.new(staff)
if service.generate_password_token!
render json: { success: false,
message: 'you will receive an email reset password instructions'
}, status: :ok
else
render json: { success: false,
message: 'Email address not found. Please check and try again.'
}, status: :not_found
end
end
|
#reset_password ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/api/dashboard/staffs_controller.rb', line 39
def reset_password
staff = Staff.find_by(reset_password_token: staff_param[:reset_password_token])
return error('Reset token is not valid.', :bad_request) if staff.blank?
service = PartnerService::Staff::ForgotPassword.new(staff, staff_param.slice(:password, :password_confirmation))
return success('Successfully change password.', :ok) if service.reset_password!
error(staff.errors.full_messages.uniq.to_sentence, :bad_request)
end
|
#show ⇒ Object
7
8
9
|
# File 'app/controllers/api/dashboard/staffs_controller.rb', line 7
def show
render json: ::Api::Dashboard::StaffSerializer.new(current_staff, set_options).as_json
end
|
#subscribe ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/controllers/api/dashboard/staffs_controller.rb', line 50
def subscribe
device = StaffDevice.find_or_initialize_by(token: params.require(:firebase_instance_id), staff: current_staff)
device.enable = true
device.lat = params.fetch(:lat, nil)
device.lng = params.fetch(:lng, nil)
message = device.store ? nil : device.errors.full_messages.to_sentence
render json: {
data: nil,
success: message.blank?,
message: message
}
rescue ActionController::ParameterMissing => e
HH_LOGGER.info(e)
render json: {
data: nil,
success: true,
message: nil
}
end
|
#unsubscribe ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'app/controllers/api/dashboard/staffs_controller.rb', line 70
def unsubscribe
device = StaffDevice.find_by(token: params.require(:firebase_instance_id), staff: current_staff)
if device.nil?
render json: {
data: nil,
success: false,
message: 'Invalid firebase instance id'
}
return
end
device.enable = false
device.save
render json: {
data: nil,
success: device.save,
message: device.errors.full_messages.to_sentence
}
end
|
#update ⇒ Object
11
12
13
14
15
16
17
|
# File 'app/controllers/api/dashboard/staffs_controller.rb', line 11
def update
if current_staff.update(staff_param)
render json: ::Api::Dashboard::StaffSerializer.new(current_staff, set_options).as_json
else
render_error(current_staff, :unprocessable_entity)
end
end
|