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 point_rules = sequelize.define( 'point_rules', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, name: { type: DataTypes.TEXT, }, description: { type: DataTypes.TEXT, }, event_type: { type: DataTypes.ENUM, values: [ "bill_payment_posted", "bill_payment_on_time", "bill_payment_minimum_met" ], }, accrual_method: { type: DataTypes.ENUM, values: [ "fixed_points", "points_per_currency_unit", "percentage_of_amount_as_points" ], }, rate: { type: DataTypes.DECIMAL, }, fixed_points: { type: DataTypes.INTEGER, }, min_payment_amount: { type: DataTypes.DECIMAL, }, max_points_per_event: { type: DataTypes.INTEGER, }, on_time_only: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, active_from: { type: DataTypes.DATE, }, active_to: { type: DataTypes.DATE, }, is_active: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); point_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.point_rules.belongsTo(db.programs, { as: 'program', foreignKey: { name: 'programId', }, constraints: false, }); db.point_rules.belongsTo(db.users, { as: 'createdBy', }); db.point_rules.belongsTo(db.users, { as: 'updatedBy', }); }; return point_rules; };