37821-vm/backend/src/db/models/experiences.js
2026-01-26 01:02:12 +00:00

148 lines
2.1 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,
},
title: {
type: DataTypes.TEXT,
},
summary: {
type: DataTypes.TEXT,
},
immersive_level: {
type: DataTypes.ENUM,
values: [
"basic",
"advanced",
"enterprise"
],
},
launch_date: {
type: DataTypes.DATE,
},
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
db.experiences.hasMany(db.testimonials, {
as: 'testimonials_related_experience',
foreignKey: {
name: 'related_experienceId',
},
constraints: false,
});
//end loop
db.experiences.belongsTo(db.organizations, {
as: 'owner',
foreignKey: {
name: 'ownerId',
},
constraints: false,
});
db.experiences.hasMany(db.file, {
as: 'hero_images',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.experiences.getTableName(),
belongsToColumn: 'hero_images',
},
});
db.experiences.hasMany(db.file, {
as: 'demo_files',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.experiences.getTableName(),
belongsToColumn: 'demo_files',
},
});
db.experiences.belongsTo(db.users, {
as: 'createdBy',
});
db.experiences.belongsTo(db.users, {
as: 'updatedBy',
});
};
return experiences;
};