summaryrefslogtreecommitdiff
path: root/app/serializers/order_serializer.rb
blob: 617918e390b6264245243ad17958eeedabaedc61 (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_orders).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