39837-vm/backend/src/db/models/timetable_entries.js
2026-04-29 14:04:12 +00:00

168 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 timetable_entries = sequelize.define(
'timetable_entries',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
day_of_week: {
type: DataTypes.ENUM,
values: [
"senin",
"selasa",
"rabu",
"kamis",
"jumat",
"sabtu"
],
},
period_number: {
type: DataTypes.INTEGER,
},
starts_at: {
type: DataTypes.DATE,
},
ends_at: {
type: DataTypes.DATE,
},
room: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
timetable_entries.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.timetable_entries.belongsTo(db.timetables, {
as: 'timetable',
foreignKey: {
name: 'timetableId',
},
constraints: false,
});
db.timetable_entries.belongsTo(db.classes, {
as: 'class',
foreignKey: {
name: 'classId',
},
constraints: false,
});
db.timetable_entries.belongsTo(db.subjects, {
as: 'subject',
foreignKey: {
name: 'subjectId',
},
constraints: false,
});
db.timetable_entries.belongsTo(db.teacher_profiles, {
as: 'teacher_profile',
foreignKey: {
name: 'teacher_profileId',
},
constraints: false,
});
db.timetable_entries.belongsTo(db.users, {
as: 'createdBy',
});
db.timetable_entries.belongsTo(db.users, {
as: 'updatedBy',
});
};
return timetable_entries;
};