User app updates

This commit is contained in:
2014-03-27 21:51:16 +01:00
parent 6af7dc74af
commit e179f6e582
37 changed files with 362 additions and 53 deletions
+4 -4
View File
@@ -1,9 +1,9 @@
class ListSerializer < Qwaiter::Serializer
# user ids for facebook pictures
embed :ids
#embed :ids
attributes :state, :needs_help, :needs_payment, :is_paid, :price, :table_id, :table_number, :section_id, :has_active_orders, :user_ids
def has_active_orders
object.has_active_orders?
end
#def has_active_orders
#object.has_active_orders?
#end
end
+14 -10
View File
@@ -1,14 +1,18 @@
class OrderSerializer < Qwaiter::Serializer
embed :ids
attributes :state, :list_id, :section_id, :product_orders, :price
embed :ids, include: true
attributes :state, :list_id, :section_id #, :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
# todo, put this logic in Ember
#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
# todo, put this logic in Ember
#def price
#product_orders.inject(0){|sum, po| sum + po[:quantity] * po[:price]}.round(2)
#end
has_many :product_orders
end
@@ -0,0 +1,5 @@
# Used for user ember1
class ProductOrderSerializer < Qwaiter::Serializer
embed :ids
attributes :order_id, :product_id, :quantity, :price
end
@@ -0,0 +1,25 @@
#class ListExtendedSerializer
#render json: {
#list: list.serialized_with_status_join_requests_and_supplier_counters.merge(order_ids: list.orders.map(&:id)),
#}
#.merge(ActiveModel::ArraySerializer.new(list.supplier.product_categories, each_serializer: ProductCategorySerializer, root: :product_categories).as_json)
#.merge(ActiveModel::ArraySerializer.new(list.orders, each_serializer: OrderSerializer, root: :orders).as_json)
#end
class UserExtendedListSerializer < Qwaiter::Serializer
# user ids for facebook pictures
self.root = :list
embed :ids, include: true
attributes :extended_version, :state, :needs_help, :needs_payment, :is_paid, :price,
:table_id, :table_number, :section_id, :user_ids,
:supplier_orders_in_process_count, :supplier_orders_placed_count
def has_active_orders
object.has_active_orders?
end
has_many :orders
has_many :product_categories
def extended_version
true
end
end
+12
View File
@@ -0,0 +1,12 @@
class UserListSerializer < Qwaiter::Serializer
# user ids for facebook pictures
#embed :ids
attributes :state, :needs_help, :needs_payment, :is_paid, :price, :table_id, :table_number, :section_id, :user_ids, :supplier_name
#def has_active_orders
#object.has_active_orders?
#end
def supplier_name
object.supplier.name
end
end