271 lines
4.1 KiB
JavaScript
271 lines
4.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 staff_members = sequelize.define(
|
|
'staff_members',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
full_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
staff_role: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"principal",
|
|
|
|
|
|
"vice_principal",
|
|
|
|
|
|
"teacher",
|
|
|
|
|
|
"registrar",
|
|
|
|
|
|
"librarian",
|
|
|
|
|
|
"admin_staff",
|
|
|
|
|
|
"it_support"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
bio: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
phone_number: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
email: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
public_profile: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
staff_members.associate = (db) => {
|
|
|
|
db.staff_members.belongsToMany(db.subjects, {
|
|
as: 'subjects_taught',
|
|
foreignKey: {
|
|
name: 'staff_members_subjects_taughtId',
|
|
},
|
|
constraints: false,
|
|
through: 'staff_membersSubjects_taughtSubjects',
|
|
});
|
|
|
|
db.staff_members.belongsToMany(db.subjects, {
|
|
as: 'subjects_taught_filter',
|
|
foreignKey: {
|
|
name: 'staff_members_subjects_taughtId',
|
|
},
|
|
constraints: false,
|
|
through: 'staff_membersSubjects_taughtSubjects',
|
|
});
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.staff_members.hasMany(db.subject_offerings, {
|
|
as: 'subject_offerings_responsible_teacher',
|
|
foreignKey: {
|
|
name: 'responsible_teacherId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.staff_members.hasMany(db.class_sections, {
|
|
as: 'class_sections_homeroom_teacher',
|
|
foreignKey: {
|
|
name: 'homeroom_teacherId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.staff_members.hasMany(db.news_posts, {
|
|
as: 'news_posts_author',
|
|
foreignKey: {
|
|
name: 'authorId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.staff_members.hasMany(db.study_materials, {
|
|
as: 'study_materials_uploaded_by',
|
|
foreignKey: {
|
|
name: 'uploaded_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.staff_members.hasMany(db.exam_results, {
|
|
as: 'exam_results_entered_by',
|
|
foreignKey: {
|
|
name: 'entered_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.staff_members.hasMany(db.attendance_sessions, {
|
|
as: 'attendance_sessions_teacher',
|
|
foreignKey: {
|
|
name: 'teacherId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.staff_members.hasMany(db.class_schedules, {
|
|
as: 'class_schedules_teacher',
|
|
foreignKey: {
|
|
name: 'teacherId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.staff_members.hasMany(db.assignments, {
|
|
as: 'assignments_teacher',
|
|
foreignKey: {
|
|
name: 'teacherId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.staff_members.hasMany(db.lesson_plans, {
|
|
as: 'lesson_plans_teacher',
|
|
foreignKey: {
|
|
name: 'teacherId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.staff_members.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.staff_members.hasMany(db.file, {
|
|
as: 'photo',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.staff_members.getTableName(),
|
|
belongsToColumn: 'photo',
|
|
},
|
|
});
|
|
|
|
|
|
db.staff_members.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.staff_members.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return staff_members;
|
|
};
|
|
|
|
|