2025-06-07 15:17:02 +00:00

102 lines
2.0 KiB
JavaScript

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: ['ToDo', 'InProgress', 'Completed'],
},
due_date: {
type: DataTypes.DATE,
},
complexity_rating: {
type: DataTypes.INTEGER,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
tasks.associate = (db) => {
db.tasks.belongsToMany(db.users, {
as: 'collaborators',
foreignKey: {
name: 'tasks_collaboratorsId',
},
constraints: false,
through: 'tasksCollaboratorsUsers',
});
db.tasks.belongsToMany(db.users, {
as: 'collaborators_filter',
foreignKey: {
name: 'tasks_collaboratorsId',
},
constraints: false,
through: 'tasksCollaboratorsUsers',
});
/// 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.users, {
as: 'assigned_to',
foreignKey: {
name: 'assigned_toId',
},
constraints: false,
});
db.tasks.belongsTo(db.workspaces, {
as: 'workspaces',
foreignKey: {
name: 'workspacesId',
},
constraints: false,
});
db.tasks.belongsTo(db.users, {
as: 'createdBy',
});
db.tasks.belongsTo(db.users, {
as: 'updatedBy',
});
};
return tasks;
};