initial commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
class List
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :state
|
||||
property :closed_at, type: Time
|
||||
has_many :orders
|
||||
belongs_to :table
|
||||
has_and_belongs_to_many :users, storing_keys: true
|
||||
|
||||
validates :table_id, presence: true
|
||||
|
||||
def close!
|
||||
self.state = 'closed'
|
||||
self.closed_at = Time.now
|
||||
save
|
||||
end
|
||||
|
||||
def supplier
|
||||
table.supplier
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
class Order
|
||||
include SimplyStored::Couch
|
||||
|
||||
belongs_to :list
|
||||
belongs_to :user
|
||||
|
||||
has_many :product_orders
|
||||
has_many :products, through: :product_orders
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
class Product
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :name
|
||||
property :code
|
||||
property :price
|
||||
|
||||
belongs_to :product_category
|
||||
belongs_to :supplier # direct! category is an aid
|
||||
has_many :product_orders
|
||||
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class ProductCategory
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :name
|
||||
belongs_to :supplier
|
||||
has_many :products
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class ProductOrder
|
||||
include SimplyStored::Couch
|
||||
|
||||
belongs_to :product
|
||||
belongs_to :order
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class Supplier
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :name
|
||||
has_many :lists
|
||||
has_many :orders, through: :lists
|
||||
has_many :products
|
||||
has_many :product_categories
|
||||
has_many :tables
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
class Table
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :number, type: Fixnum, default: 1
|
||||
|
||||
belongs_to :supplier
|
||||
has_many :lists
|
||||
|
||||
validates :supplier_id, presence: true
|
||||
#validates :list_id, presence: true
|
||||
validates :number, numericality: {greater_than: 0}
|
||||
|
||||
view :active_lists, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
emit(doc._id, 1);
|
||||
}
|
||||
}|, reduce_function: '_sum'
|
||||
|
||||
def occupied?
|
||||
not self.class.database.view(self.class.active_lists(key: list_id, reduce: true)).zero?
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class User
|
||||
include SimplyStored::Couch
|
||||
include Devise::Orm::SimplyStored
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable
|
||||
|
||||
has_and_belongs_to_many :lists, storing_keys: false
|
||||
has_many :orders
|
||||
|
||||
validates_uniqueness_of :email
|
||||
end
|
||||
Reference in New Issue
Block a user