204 lines
3.4 KiB
JavaScript
204 lines
3.4 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.students, {
|
|
as: 'students_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.teachers, {
|
|
as: 'teachers_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.parents, {
|
|
as: 'parents_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.classes, {
|
|
as: 'classes_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.subjects, {
|
|
as: 'subjects_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.timetables, {
|
|
as: 'timetables_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.exams, {
|
|
as: 'exams_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.exam_results, {
|
|
as: 'exam_results_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.fees, {
|
|
as: 'fees_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.payments, {
|
|
as: 'payments_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.announcements, {
|
|
as: 'announcements_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.notifications, {
|
|
as: 'notifications_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.schools.hasMany(db.audit_logs, {
|
|
as: 'audit_logs_schools',
|
|
foreignKey: {
|
|
name: 'schoolsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.schools.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.schools.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return schools;
|
|
};
|
|
|
|
|