30926/backend/src/db/models/assignments.js
2025-04-23 05:18:14 +00:00

90 lines
1.8 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 assignments = sequelize.define(
'assignments',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
task_description: {
type: DataTypes.TEXT,
},
urgency: {
type: DataTypes.ENUM,
values: ['Low', 'Medium', 'High'],
},
preferred_date: {
type: DataTypes.DATE,
},
status: {
type: DataTypes.ENUM,
values: ['Pending', 'InProgress', 'OnHold', 'Resolved'],
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
assignments.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.assignments.belongsTo(db.engineers, {
as: 'engineer',
foreignKey: {
name: 'engineerId',
},
constraints: false,
});
db.assignments.belongsTo(db.clients, {
as: 'client',
foreignKey: {
name: 'clientId',
},
constraints: false,
});
db.assignments.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.assignments.belongsTo(db.users, {
as: 'createdBy',
});
db.assignments.belongsTo(db.users, {
as: 'updatedBy',
});
};
return assignments;
};