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 actions = sequelize.define( 'actions', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, title: { type: DataTypes.TEXT, }, start_date: { type: DataTypes.DATE, }, due_date: { type: DataTypes.DATE, }, status: { type: DataTypes.ENUM, values: ['open', 'in-progress', 'completed'], }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); actions.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.actions.belongsTo(db.users, { as: 'assignee', foreignKey: { name: 'assigneeId', }, constraints: false, }); db.actions.belongsTo(db.incidents, { as: 'incident', foreignKey: { name: 'incidentId', }, constraints: false, }); db.actions.belongsTo(db.companies, { as: 'companies', foreignKey: { name: 'companiesId', }, constraints: false, }); db.actions.belongsTo(db.users, { as: 'createdBy', }); db.actions.belongsTo(db.users, { as: 'updatedBy', }); }; return actions; };