Class: Dscf::Marketplace::ListingApprovalsController

Inherits:
ApplicationController show all
Includes:
Core::Common
Defined in:
app/controllers/dscf/marketplace/listing_approvals_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#bypass_permissions_for_demo?, #pundit_user

Instance Method Details

#set_priceObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/dscf/marketplace/listing_approvals_controller.rb', line 6

def set_price
  set_object
  authorize @obj, :set_price?

  if @obj.update(set_price_params.merge(approved_by: current_user, approved_at: Time.current))
    notification = Dscf::Core::Notification.create!(
      notification_type: :listing,
      title: "Price set for listing ##{@obj.listing_id}",
      body: "Aggregator price: #{@obj.aggregator_price}, Supplier price: #{@obj.supplier_price}",
      recipient: current_user,
      notifiable: @obj
    )
    Dscf::Core::NotificationService.deliver(notification)
    render_success(data: @obj, serializer_options: {include: serializer_includes_for_action(:show)})
  else
    render_error(errors: @obj.errors.full_messages[0], status: :unprocessable_entity)
  end
end