243 lines
3.4 KiB
JavaScript
243 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 accreditation_cases = sequelize.define(
|
|
'accreditation_cases',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
case_number: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"in_progress",
|
|
|
|
|
|
"on_hold",
|
|
|
|
|
|
"approved",
|
|
|
|
|
|
"rejected",
|
|
|
|
|
|
"withdrawn"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
smart_score: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
score_grade: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"green",
|
|
|
|
|
|
"yellow",
|
|
|
|
|
|
"red",
|
|
|
|
|
|
"unknown"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
needs_attention: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
submitted_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
decision_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
due_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
public_notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
internal_notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
accreditation_cases.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.accreditation_cases.hasMany(db.case_documents, {
|
|
as: 'case_documents_accreditation_case',
|
|
foreignKey: {
|
|
name: 'accreditation_caseId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.accreditation_cases.hasMany(db.reviews, {
|
|
as: 'reviews_accreditation_case',
|
|
foreignKey: {
|
|
name: 'accreditation_caseId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.accreditation_cases.hasMany(db.case_timeline_events, {
|
|
as: 'case_timeline_events_accreditation_case',
|
|
foreignKey: {
|
|
name: 'accreditation_caseId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.accreditation_cases.belongsTo(db.accreditation_programs, {
|
|
as: 'program',
|
|
foreignKey: {
|
|
name: 'programId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.accreditation_cases.belongsTo(db.applicants, {
|
|
as: 'applicant',
|
|
foreignKey: {
|
|
name: 'applicantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.accreditation_cases.belongsTo(db.accreditation_stages, {
|
|
as: 'current_stage',
|
|
foreignKey: {
|
|
name: 'current_stageId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.accreditation_cases.belongsTo(db.users, {
|
|
as: 'assigned_reviewer',
|
|
foreignKey: {
|
|
name: 'assigned_reviewerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.accreditation_cases.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.accreditation_cases.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.accreditation_cases.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return accreditation_cases;
|
|
};
|
|
|
|
|