157 lines
2.1 KiB
JavaScript
157 lines
2.1 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 promotions = sequelize.define(
|
|
'promotions',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
code: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
start_date: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
end_date: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
active: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
discount_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"Percentage",
|
|
|
|
|
|
"Fixed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
discount_value: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
promotions.associate = (db) => {
|
|
|
|
db.promotions.belongsToMany(db.inventory_items, {
|
|
as: 'applicable_items',
|
|
foreignKey: {
|
|
name: 'promotions_applicable_itemsId',
|
|
},
|
|
constraints: false,
|
|
through: 'promotionsApplicable_itemsInventory_items',
|
|
});
|
|
|
|
db.promotions.belongsToMany(db.inventory_items, {
|
|
as: 'applicable_items_filter',
|
|
foreignKey: {
|
|
name: 'promotions_applicable_itemsId',
|
|
},
|
|
constraints: false,
|
|
through: 'promotionsApplicable_itemsInventory_items',
|
|
});
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.promotions.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.promotions.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return promotions;
|
|
};
|
|
|
|
|