207 lines
4.9 KiB
JavaScript
207 lines
4.9 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const GuarantorForms = db.guarantor_forms;
|
|
|
|
const Participants = db.participants;
|
|
|
|
const GuarantorFormsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "files" field
|
|
|
|
submission_date: new Date('2023-10-01T10:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "files" field
|
|
|
|
submission_date: new Date('2023-09-15T14:30:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "files" field
|
|
|
|
submission_date: new Date('2023-10-05T09:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "files" field
|
|
|
|
submission_date: new Date('2023-09-20T11:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const ParticipantsData = [
|
|
{
|
|
first_name: 'Alice',
|
|
|
|
last_name: 'Johnson',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
form_status: 'complete',
|
|
|
|
form_completion_date: new Date('2023-10-01T10:00:00Z'),
|
|
},
|
|
|
|
{
|
|
first_name: 'Bob',
|
|
|
|
last_name: 'Williams',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
form_status: 'complete',
|
|
|
|
form_completion_date: new Date('2023-09-15T14:30:00Z'),
|
|
},
|
|
|
|
{
|
|
first_name: 'Charlie',
|
|
|
|
last_name: 'Brown',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
form_status: 'complete',
|
|
|
|
form_completion_date: new Date('2023-10-05T09:00:00Z'),
|
|
},
|
|
|
|
{
|
|
first_name: 'Diana',
|
|
|
|
last_name: 'Evans',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
form_status: 'pending',
|
|
|
|
form_completion_date: new Date('2023-09-20T11:00:00Z'),
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateGuarantorFormWithParticipant() {
|
|
const relatedParticipant0 = await Participants.findOne({
|
|
offset: Math.floor(Math.random() * (await Participants.count())),
|
|
});
|
|
const GuarantorForm0 = await GuarantorForms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (GuarantorForm0?.setParticipant) {
|
|
await GuarantorForm0.setParticipant(relatedParticipant0);
|
|
}
|
|
|
|
const relatedParticipant1 = await Participants.findOne({
|
|
offset: Math.floor(Math.random() * (await Participants.count())),
|
|
});
|
|
const GuarantorForm1 = await GuarantorForms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (GuarantorForm1?.setParticipant) {
|
|
await GuarantorForm1.setParticipant(relatedParticipant1);
|
|
}
|
|
|
|
const relatedParticipant2 = await Participants.findOne({
|
|
offset: Math.floor(Math.random() * (await Participants.count())),
|
|
});
|
|
const GuarantorForm2 = await GuarantorForms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (GuarantorForm2?.setParticipant) {
|
|
await GuarantorForm2.setParticipant(relatedParticipant2);
|
|
}
|
|
|
|
const relatedParticipant3 = await Participants.findOne({
|
|
offset: Math.floor(Math.random() * (await Participants.count())),
|
|
});
|
|
const GuarantorForm3 = await GuarantorForms.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (GuarantorForm3?.setParticipant) {
|
|
await GuarantorForm3.setParticipant(relatedParticipant3);
|
|
}
|
|
}
|
|
|
|
async function associateParticipantWithCoordinator() {
|
|
const relatedCoordinator0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Participant0 = await Participants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Participant0?.setCoordinator) {
|
|
await Participant0.setCoordinator(relatedCoordinator0);
|
|
}
|
|
|
|
const relatedCoordinator1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Participant1 = await Participants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Participant1?.setCoordinator) {
|
|
await Participant1.setCoordinator(relatedCoordinator1);
|
|
}
|
|
|
|
const relatedCoordinator2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Participant2 = await Participants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Participant2?.setCoordinator) {
|
|
await Participant2.setCoordinator(relatedCoordinator2);
|
|
}
|
|
|
|
const relatedCoordinator3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Participant3 = await Participants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Participant3?.setCoordinator) {
|
|
await Participant3.setCoordinator(relatedCoordinator3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await GuarantorForms.bulkCreate(GuarantorFormsData);
|
|
|
|
await Participants.bulkCreate(ParticipantsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateGuarantorFormWithParticipant(),
|
|
|
|
await associateParticipantWithCoordinator(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('guarantor_forms', null, {});
|
|
|
|
await queryInterface.bulkDelete('participants', null, {});
|
|
},
|
|
};
|