30421/backend/src/db/models/hr_managers.js
2025-04-03 11:13:17 +00:00

80 lines
1.7 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 hr_managers = sequelize.define(
'hr_managers',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
email: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
hr_managers.associate = (db) => {
db.hr_managers.belongsToMany(db.recruiters, {
as: 'recruiters',
foreignKey: {
name: 'hr_managers_recruitersId',
},
constraints: false,
through: 'hr_managersRecruitersRecruiters',
});
db.hr_managers.belongsToMany(db.recruiters, {
as: 'recruiters_filter',
foreignKey: {
name: 'hr_managers_recruitersId',
},
constraints: false,
through: 'hr_managersRecruitersRecruiters',
});
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.hr_managers.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.hr_managers.belongsTo(db.users, {
as: 'createdBy',
});
db.hr_managers.belongsTo(db.users, {
as: 'updatedBy',
});
};
return hr_managers;
};