32839/backend/src/db/models/assignments.js
2025-07-15 19:55:51 +00:00

82 lines
1.6 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_name: {
type: DataTypes.TEXT,
},
start_time: {
type: DataTypes.DATE,
},
end_time: {
type: DataTypes.DATE,
},
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.campaigns, {
as: 'campaign',
foreignKey: {
name: 'campaignId',
},
constraints: false,
});
db.assignments.belongsTo(db.users, {
as: 'assigned_to',
foreignKey: {
name: 'assigned_toId',
},
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;
};