209 lines
2.6 KiB
JavaScript
209 lines
2.6 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 exams = sequelize.define(
|
|
'exams',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
exam_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"monthly",
|
|
|
|
|
|
"midterm",
|
|
|
|
|
|
"final",
|
|
|
|
|
|
"national_grade_8",
|
|
|
|
|
|
"national_grade_10",
|
|
|
|
|
|
"national_grade_12"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
starts_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
ends_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
public_results: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
exams.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.exams.hasMany(db.exam_results, {
|
|
as: 'exam_results_exam',
|
|
foreignKey: {
|
|
name: 'examId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.exams.hasMany(db.exam_performance_summaries, {
|
|
as: 'exam_performance_summaries_exam',
|
|
foreignKey: {
|
|
name: 'examId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.exams.hasMany(db.top_student_features, {
|
|
as: 'top_student_features_exam',
|
|
foreignKey: {
|
|
name: 'examId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.exams.belongsTo(db.school_years, {
|
|
as: 'school_year',
|
|
foreignKey: {
|
|
name: 'school_yearId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.exams.belongsTo(db.terms, {
|
|
as: 'term',
|
|
foreignKey: {
|
|
name: 'termId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.exams.belongsTo(db.grades, {
|
|
as: 'grade',
|
|
foreignKey: {
|
|
name: 'gradeId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.exams.belongsTo(db.streams, {
|
|
as: 'stream',
|
|
foreignKey: {
|
|
name: 'streamId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.exams.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.exams.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return exams;
|
|
};
|
|
|
|
|