39136-vm/backend/src/db/models/registration_forms.js
2026-03-11 16:01:32 +00:00

390 lines
4.8 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 registration_forms = sequelize.define(
'registration_forms',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
form_code: {
type: DataTypes.TEXT,
},
submitted_at: {
type: DataTypes.DATE,
},
status: {
type: DataTypes.ENUM,
values: [
"baru",
"verifikasi",
"tes",
"diterima",
"ditolak",
"cadangan"
],
},
student_full_name: {
type: DataTypes.TEXT,
},
student_gender: {
type: DataTypes.ENUM,
values: [
"male"
],
},
nik: {
type: DataTypes.TEXT,
},
nisn: {
type: DataTypes.TEXT,
},
birth_place: {
type: DataTypes.TEXT,
},
birth_date: {
type: DataTypes.DATE,
},
address: {
type: DataTypes.TEXT,
},
village: {
type: DataTypes.TEXT,
},
district: {
type: DataTypes.TEXT,
},
city: {
type: DataTypes.TEXT,
},
province: {
type: DataTypes.TEXT,
},
postal_code: {
type: DataTypes.TEXT,
},
student_phone: {
type: DataTypes.TEXT,
},
father_name: {
type: DataTypes.TEXT,
},
mother_name: {
type: DataTypes.TEXT,
},
parent_phone: {
type: DataTypes.TEXT,
},
parent_email: {
type: DataTypes.TEXT,
},
previous_education_level: {
type: DataTypes.ENUM,
values: [
"sd",
"smp",
"mts",
"sma",
"smk",
"ma",
"ponpes",
"lainnya"
],
},
previous_school_name: {
type: DataTypes.TEXT,
},
tahfidz_experience: {
type: DataTypes.TEXT,
},
memorization_juz: {
type: DataTypes.INTEGER,
},
health_notes: {
type: DataTypes.TEXT,
},
special_needs: {
type: DataTypes.TEXT,
},
admin_notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
registration_forms.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.registration_forms.hasMany(db.registration_documents, {
as: 'registration_documents_registration_form',
foreignKey: {
name: 'registration_formId',
},
constraints: false,
});
db.registration_forms.hasMany(db.payments, {
as: 'payments_registration_form',
foreignKey: {
name: 'registration_formId',
},
constraints: false,
});
db.registration_forms.hasMany(db.test_results, {
as: 'test_results_registration_form',
foreignKey: {
name: 'registration_formId',
},
constraints: false,
});
db.registration_forms.hasMany(db.status_histories, {
as: 'status_histories_registration_form',
foreignKey: {
name: 'registration_formId',
},
constraints: false,
});
db.registration_forms.hasMany(db.outbound_messages, {
as: 'outbound_messages_registration_form',
foreignKey: {
name: 'registration_formId',
},
constraints: false,
});
//end loop
db.registration_forms.belongsTo(db.ppdb_waves, {
as: 'ppdb_wave',
foreignKey: {
name: 'ppdb_waveId',
},
constraints: false,
});
db.registration_forms.belongsTo(db.programs, {
as: 'program',
foreignKey: {
name: 'programId',
},
constraints: false,
});
db.registration_forms.belongsTo(db.dormitories, {
as: 'dormitory',
foreignKey: {
name: 'dormitoryId',
},
constraints: false,
});
db.registration_forms.belongsTo(db.users, {
as: 'submitted_by',
foreignKey: {
name: 'submitted_byId',
},
constraints: false,
});
db.registration_forms.belongsTo(db.users, {
as: 'createdBy',
});
db.registration_forms.belongsTo(db.users, {
as: 'updatedBy',
});
};
return registration_forms;
};