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 orders = sequelize.define( 'orders', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, order_id: { type: DataTypes.INTEGER, }, status: { type: DataTypes.ENUM, values: ['Processing', 'Ironing', 'Ready'], }, rental_start_date: { type: DataTypes.DATE, }, rental_end_date: { type: DataTypes.DATE, }, commission_amount: { type: DataTypes.DECIMAL, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); orders.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.orders.belongsTo(db.customers, { as: 'customer', foreignKey: { name: 'customerId', }, constraints: false, }); db.orders.belongsTo(db.products, { as: 'item', foreignKey: { name: 'itemId', }, constraints: false, }); db.orders.belongsTo(db.staff, { as: 'staff', foreignKey: { name: 'staffId', }, constraints: false, }); db.orders.belongsTo(db.users, { as: 'createdBy', }); db.orders.belongsTo(db.users, { as: 'updatedBy', }); }; return orders; };