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 dynamic_pricing_rules = sequelize.define( 'dynamic_pricing_rules', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, name: { type: DataTypes.TEXT, }, rule_type: { type: DataTypes.ENUM, values: [ "occupancy_based", "days_before_arrival", "day_of_week", "length_of_stay" ], }, adjustment_percent: { type: DataTypes.DECIMAL, }, adjustment_amount: { type: DataTypes.DECIMAL, }, min_occupancy_percent: { type: DataTypes.INTEGER, }, max_occupancy_percent: { type: DataTypes.INTEGER, }, min_days_before: { type: DataTypes.INTEGER, }, max_days_before: { type: DataTypes.INTEGER, }, applies_days_of_week: { type: DataTypes.TEXT, }, active: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); dynamic_pricing_rules.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.dynamic_pricing_rules.belongsTo(db.hotels, { as: 'hotel', foreignKey: { name: 'hotelId', }, constraints: false, }); db.dynamic_pricing_rules.belongsTo(db.room_types, { as: 'room_type', foreignKey: { name: 'room_typeId', }, constraints: false, }); db.dynamic_pricing_rules.belongsTo(db.rate_plans, { as: 'rate_plan', foreignKey: { name: 'rate_planId', }, constraints: false, }); db.dynamic_pricing_rules.belongsTo(db.organizations, { as: 'organizations', foreignKey: { name: 'organizationsId', }, constraints: false, }); db.dynamic_pricing_rules.belongsTo(db.users, { as: 'createdBy', }); db.dynamic_pricing_rules.belongsTo(db.users, { as: 'updatedBy', }); }; return dynamic_pricing_rules; };