199 lines
2.6 KiB
JavaScript
199 lines
2.6 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
const order_items = sequelize.define(
|
|
'order_items',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
item_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"pizza",
|
|
|
|
|
|
"beverage",
|
|
|
|
|
|
"add_on"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
quantity: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
unit_price: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
total_price: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
item_note: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
pizza_category: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"savory",
|
|
|
|
|
|
"sweet"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
order_items.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.order_items.belongsTo(db.orders, {
|
|
as: 'order',
|
|
foreignKey: {
|
|
name: 'orderId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.order_items.belongsTo(db.pizza_sizes, {
|
|
as: 'pizza_size',
|
|
foreignKey: {
|
|
name: 'pizza_sizeId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.order_items.belongsTo(db.stuffed_crusts, {
|
|
as: 'stuffed_crust',
|
|
foreignKey: {
|
|
name: 'stuffed_crustId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.order_items.belongsTo(db.pizza_flavors, {
|
|
as: 'flavor_primary',
|
|
foreignKey: {
|
|
name: 'flavor_primaryId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.order_items.belongsTo(db.pizza_flavors, {
|
|
as: 'flavor_secondary',
|
|
foreignKey: {
|
|
name: 'flavor_secondaryId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.order_items.belongsTo(db.beverages, {
|
|
as: 'beverage',
|
|
foreignKey: {
|
|
name: 'beverageId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.order_items.belongsTo(db.add_ons, {
|
|
as: 'add_on',
|
|
foreignKey: {
|
|
name: 'add_onId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.order_items.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.order_items.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return order_items;
|
|
};
|
|
|
|
|