summaryrefslogtreecommitdiff
path: root/app/serializers/order_serializer.rb
blob: e6883bf4adfd62a7c6a247aa9f8e454d2df7cc10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# frozen_string_literal: true

# OrderSerializer
class OrderSerializer < BaseSerializer
  attributes :public_id, :created_at
  attribute :products do |object|
    ProductSerializer.new(
      Product.joins(:product_order).select('products.*', 'product_orders.quantity AS quantity')
                                   .includes(picture_attachment: :blob).where('product_orders.order_id = ?', object.id)
    ).serializable_hash
  end

  attribute :total do |object|
    object.payment.total
  end
end