40285-vm/backend/src/db/models/job_applications.js
2026-06-18 21:11:44 +00:00

186 lines
2.2 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 job_applications = sequelize.define(
'job_applications',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
status: {
type: DataTypes.ENUM,
values: [
"submitted",
"shortlisted",
"interview",
"offer",
"hired",
"rejected",
"withdrawn"
],
},
cover_letter: {
type: DataTypes.TEXT,
},
applied_at: {
type: DataTypes.DATE,
},
last_updated_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
job_applications.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.job_applications.belongsTo(db.job_listings, {
as: 'job_listing',
foreignKey: {
name: 'job_listingId',
},
constraints: false,
});
db.job_applications.belongsTo(db.users, {
as: 'applicant',
foreignKey: {
name: 'applicantId',
},
constraints: false,
});
db.job_applications.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.job_applications.hasMany(db.file, {
as: 'resume_files',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.job_applications.getTableName(),
belongsToColumn: 'resume_files',
},
});
db.job_applications.belongsTo(db.users, {
as: 'createdBy',
});
db.job_applications.belongsTo(db.users, {
as: 'updatedBy',
});
};
return job_applications;
};