Flatlogic Bot 95aef58de7 v1
2026-01-06 15:05:00 +00:00

199 lines
2.4 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",
"InReview",
"Blocked",
"Done"
],
},
priority: {
type: DataTypes.ENUM,
values: [
"Low",
"Medium",
"High",
"Critical"
],
},
start_date: {
type: DataTypes.DATE,
},
due_date: {
type: DataTypes.DATE,
},
estimated_hours: {
type: DataTypes.DECIMAL,
},
spent_hours: {
type: DataTypes.DECIMAL,
},
completed: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
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.projects, {
as: 'project',
foreignKey: {
name: 'projectId',
},
constraints: false,
});
db.tasks.belongsTo(db.users, {
as: 'assignee',
foreignKey: {
name: 'assigneeId',
},
constraints: false,
});
db.tasks.belongsTo(db.users, {
as: 'reporter',
foreignKey: {
name: 'reporterId',
},
constraints: false,
});
db.tasks.hasMany(db.file, {
as: 'attachments',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.tasks.getTableName(),
belongsToColumn: 'attachments',
},
});
db.tasks.belongsTo(db.users, {
as: 'createdBy',
});
db.tasks.belongsTo(db.users, {
as: 'updatedBy',
});
};
return tasks;
};