diff options
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/order_serializer.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/serializers/order_serializer.rb b/app/serializers/order_serializer.rb new file mode 100644 index 0000000..e6883bf --- /dev/null +++ b/app/serializers/order_serializer.rb @@ -0,0 +1,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 |