31298/backend/src/db/models/curriculums.js
2025-05-06 19:03:34 +00:00

78 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 curriculums = sequelize.define(
'curriculums',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
curriculums.associate = (db) => {
db.curriculums.belongsToMany(db.lesson_plans, {
as: 'lesson_plans',
foreignKey: {
name: 'curriculums_lesson_plansId',
},
constraints: false,
through: 'curriculumsLesson_plansLesson_plans',
});
db.curriculums.belongsToMany(db.lesson_plans, {
as: 'lesson_plans_filter',
foreignKey: {
name: 'curriculums_lesson_plansId',
},
constraints: false,
through: 'curriculumsLesson_plansLesson_plans',
});
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.curriculums.hasMany(db.file, {
as: 'pdf_documents',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.curriculums.getTableName(),
belongsToColumn: 'pdf_documents',
},
});
db.curriculums.belongsTo(db.users, {
as: 'createdBy',
});
db.curriculums.belongsTo(db.users, {
as: 'updatedBy',
});
};
return curriculums;
};