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 monthly_training_calendars = sequelize.define( 'monthly_training_calendars', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, path_choice: { type: DataTypes.ENUM, values: [ "real_life", "blue_lock" ], }, month_start_at: { type: DataTypes.DATE, }, month_end_at: { type: DataTypes.DATE, }, title: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); monthly_training_calendars.associate = (db) => { /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity db.monthly_training_calendars.hasMany(db.daily_challenges, { as: 'daily_challenges_monthly_training_calendar', foreignKey: { name: 'monthly_training_calendarId', }, constraints: false, }); //end loop db.monthly_training_calendars.belongsTo(db.users, { as: 'user', foreignKey: { name: 'userId', }, constraints: false, }); db.monthly_training_calendars.belongsTo(db.nel_teams, { as: 'nel_team', foreignKey: { name: 'nel_teamId', }, constraints: false, }); db.monthly_training_calendars.belongsTo(db.users, { as: 'createdBy', }); db.monthly_training_calendars.belongsTo(db.users, { as: 'updatedBy', }); }; return monthly_training_calendars; };