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 tasks = sequelize.define( 'tasks', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, title: { type: DataTypes.TEXT, }, description: { type: DataTypes.TEXT, }, status: { type: DataTypes.ENUM, values: ['backlog', 'todo', 'in_progress', 'review', 'completed'], }, priority: { type: DataTypes.ENUM, values: ['low', 'medium', 'high', 'urgent'], }, due_date: { type: DataTypes.DATE, }, time_estimate: { type: DataTypes.DECIMAL, }, tags: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); tasks.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.tasks.belongsTo(db.participants, { as: 'participant', foreignKey: { name: 'participantId', }, constraints: false, }); db.tasks.belongsTo(db.users, { as: 'assignee', foreignKey: { name: 'assigneeId', }, constraints: false, }); db.tasks.belongsTo(db.users, { as: 'creator', foreignKey: { name: 'creatorId', }, constraints: false, }); db.tasks.belongsTo(db.goals, { as: 'related_goal', foreignKey: { name: 'related_goalId', }, constraints: false, }); db.tasks.belongsTo(db.tasks, { as: 'parent_task', foreignKey: { name: 'parent_taskId', }, constraints: false, }); db.tasks.belongsTo(db.users, { as: 'createdBy', }); db.tasks.belongsTo(db.users, { as: 'updatedBy', }); }; return tasks; };