285 lines
5.0 KiB
JavaScript
285 lines
5.0 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 schools = sequelize.define(
|
|
'schools',
|
|
{
|
|
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,
|
|
},
|
|
);
|
|
|
|
schools.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
db.schools.hasMany(db.users, {
|
|
as: 'users_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
db.schools.hasMany(db.academic_years, {
|
|
as: 'academic_years_school',
|
|
foreignKey: {
|
|
name: 'schoolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.education_levels, {
|
|
as: 'education_levels_school',
|
|
foreignKey: {
|
|
name: 'schoolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.classes, {
|
|
as: 'classes_school',
|
|
foreignKey: {
|
|
name: 'schoolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.students, {
|
|
as: 'students_school',
|
|
foreignKey: {
|
|
name: 'schoolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.parent_student_links, {
|
|
as: 'parent_student_links_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.subjects, {
|
|
as: 'subjects_school',
|
|
foreignKey: {
|
|
name: 'schoolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.class_subjects, {
|
|
as: 'class_subjects_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.timetable_entries, {
|
|
as: 'timetable_entries_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.attendance_sessions, {
|
|
as: 'attendance_sessions_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.attendance_records, {
|
|
as: 'attendance_records_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.announcements, {
|
|
as: 'announcements_school',
|
|
foreignKey: {
|
|
name: 'schoolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.assignments, {
|
|
as: 'assignments_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.assignment_submissions, {
|
|
as: 'assignment_submissions_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.exam_categories, {
|
|
as: 'exam_categories_school',
|
|
foreignKey: {
|
|
name: 'schoolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.exams, {
|
|
as: 'exams_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.exam_questions, {
|
|
as: 'exam_questions_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.exam_question_choices, {
|
|
as: 'exam_question_choices_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.exam_attempts, {
|
|
as: 'exam_attempts_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.exam_answers, {
|
|
as: 'exam_answers_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.fee_definitions, {
|
|
as: 'fee_definitions_school',
|
|
foreignKey: {
|
|
name: 'schoolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.billing_items, {
|
|
as: 'billing_items_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.payments, {
|
|
as: 'payments_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.notification_logs, {
|
|
as: 'notification_logs_school',
|
|
foreignKey: {
|
|
name: 'schoolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.schools.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.schools.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return schools;
|
|
};
|
|
|
|
|