37775-vm/backend/src/db/models/students.js
2026-01-24 12:24:37 +00:00

139 lines
1.9 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 students = sequelize.define(
'students',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
full_name: {
type: DataTypes.TEXT,
},
first_name: {
type: DataTypes.TEXT,
},
last_name: {
type: DataTypes.TEXT,
},
student_number: {
type: DataTypes.TEXT,
},
birthdate: {
type: DataTypes.DATE,
},
active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
students.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.students.hasMany(db.student_logs, {
as: 'student_logs_student',
foreignKey: {
name: 'studentId',
},
constraints: false,
});
db.students.hasMany(db.incident_reports, {
as: 'incident_reports_student',
foreignKey: {
name: 'studentId',
},
constraints: false,
});
//end loop
db.students.belongsTo(db.classrooms, {
as: 'classroom',
foreignKey: {
name: 'classroomId',
},
constraints: false,
});
db.students.belongsTo(db.users, {
as: 'createdBy',
});
db.students.belongsTo(db.users, {
as: 'updatedBy',
});
};
return students;
};