32697/backend/src/db/models/communications.js
2025-07-08 23:30:43 +00:00

78 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 communications = sequelize.define(
'communications',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
message: {
type: DataTypes.TEXT,
},
sent_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
communications.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.communications.belongsTo(db.candidates, {
as: 'candidate',
foreignKey: {
name: 'candidateId',
},
constraints: false,
});
db.communications.belongsTo(db.users, {
as: 'poc',
foreignKey: {
name: 'pocId',
},
constraints: false,
});
db.communications.belongsTo(db.companies, {
as: 'companies',
foreignKey: {
name: 'companiesId',
},
constraints: false,
});
db.communications.belongsTo(db.users, {
as: 'createdBy',
});
db.communications.belongsTo(db.users, {
as: 'updatedBy',
});
};
return communications;
};