Files
mozo-backend/app/serializers/order_serializer.rb
T

15 lines
496 B
Ruby

class OrderSerializer < Qwaiter::Serializer
embed :ids
attributes :state, :list_id, :section_id, :product_orders, :price
def product_orders
@product_orders ||= object.product_orders.include_relation(:product) .map do |product_order|
{product_name: product_order.product.name, id: product_order.id, quantity: product_order.quantity, price: product_order.price}
end
end
def price
product_orders.inject(0){|sum, po| sum + po[:quantity] * po[:price]}.round(2)
end
end