39243-vm/backend/src/db/models/experiences.js
2026-03-19 13:59:36 +00:00

177 lines
2.0 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 experiences = sequelize.define(
'experiences',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
type: {
type: DataTypes.ENUM,
values: [
"work",
"education",
"freelance",
"internship",
"volunteering",
"certification"
],
},
title: {
type: DataTypes.TEXT,
},
organization: {
type: DataTypes.TEXT,
},
location: {
type: DataTypes.TEXT,
},
start_date: {
type: DataTypes.DATE,
},
end_date: {
type: DataTypes.DATE,
},
is_current: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
summary: {
type: DataTypes.TEXT,
},
sort_order: {
type: DataTypes.INTEGER,
},
is_visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
experiences.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.experiences.belongsTo(db.personal_profiles, {
as: 'profile',
foreignKey: {
name: 'profileId',
},
constraints: false,
});
db.experiences.belongsTo(db.users, {
as: 'createdBy',
});
db.experiences.belongsTo(db.users, {
as: 'updatedBy',
});
};
return experiences;
};