From 4b0527efc4b7703c99043013fd455f496d32329c Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 13 Apr 2023 18:14:35 -0600 Subject: AƱade OrdersController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/serializers/order_serializer.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/serializers/order_serializer.rb (limited to 'app/serializers') 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 -- cgit v1.2.3