Class: Dscf::Marketplace::AgentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- Dscf::Marketplace::AgentsController
- Includes:
- Core::Common
- Defined in:
- app/controllers/dscf/marketplace/agents_controller.rb
Instance Method Summary collapse
- #destroy ⇒ Object
-
#modify_location ⇒ Object
Modify agent’s location fields.
- #register ⇒ Object
-
#verify ⇒ Object
Verify (approve) or reject an agent based on presence of reason param.
Methods inherited from ApplicationController
#bypass_permissions_for_demo?, #pundit_user
Instance Method Details
#destroy ⇒ Object
20 21 22 23 24 25 |
# File 'app/controllers/dscf/marketplace/agents_controller.rb', line 20 def destroy @obj = find_record @obj @obj.destroy! render_success("agent.success.destroy") end |
#modify_location ⇒ Object
Modify agent’s location fields
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/dscf/marketplace/agents_controller.rb', line 56 def modify_location @obj = find_record @obj, :modify_location? @obj.update!( service_area: params[:service_area], sub_city: params[:sub_city], woreda: params[:woreda], modified_at: Time.current ) notification = Dscf::Core::Notification.create!( notifiable: @obj, recipient: current_user, notification_type: :modification, title: "Agent Location Modified", body: "Location for agent '#{@obj.name}' (#{@obj.code}) has been updated." ) Dscf::Core::NotificationService.deliver(notification) render_success("agent.success.location_modified", data: @obj) rescue StandardError => e render_error(errors: e., status: :unprocessable_entity) end |
#register ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/dscf/marketplace/agents_controller.rb', line 6 def register @clazz.new, :register? obj = @clazz.new(registration_params) ActiveRecord::Base.transaction do if obj.save create_registration_notification(obj) render_success("agent.success.register", data: obj, status: :created) else render_error("agent.errors.register", errors: obj.errors.[0], status: :unprocessable_entity) end end end |
#verify ⇒ Object
Verify (approve) or reject an agent based on presence of reason param
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/dscf/marketplace/agents_controller.rb', line 28 def verify @obj = find_record @obj, :verify? if params[:reason].present? @obj.update!( verification_status: :rejected, rejection_reason: params[:reason], rejected_at: Time.current ) notification = Dscf::Core::Notification.create!( notifiable: @obj, recipient: current_user, notification_type: :rejection, title: "Agent Rejected", body: "Agent '#{@obj.name}' (#{@obj.code}) has been rejected. Reason: #{params[:reason]}" ) Dscf::Core::NotificationService.deliver(notification) render_success("agent.success.rejected", data: @obj) else @obj.update!(verification_status: :verified) render_success("agent.success.verified", data: @obj) end rescue StandardError => e render_error(errors: e., status: :unprocessable_entity) end |