39103-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-03-11 02:14:19 +00:00

3295 lines
59 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const ScholarshipTypes = db.scholarship_types;
const Scholarships = db.scholarships;
const Schools = db.schools;
const Scholars = db.scholars;
const Applications = db.applications;
const ApplicationReviews = db.application_reviews;
const ScholarAwards = db.scholar_awards;
const DashboardTiles = db.dashboard_tiles;
const ScholarshipTypesData = [
{
"name": "Marie Curie",
"code": "Ada Lovelace",
"description": "Ada Lovelace",
"active": true,
},
{
"name": "Grace Hopper",
"code": "Marie Curie",
"description": "Marie Curie",
"active": true,
},
{
"name": "Ada Lovelace",
"code": "Ada Lovelace",
"description": "Ada Lovelace",
"active": false,
},
{
"name": "Grace Hopper",
"code": "Ada Lovelace",
"description": "Alan Turing",
"active": true,
},
];
const ScholarshipsData = [
{
"name": "Marie Curie",
"code": "Ada Lovelace",
// type code here for "relation_one" field
"education_level": "high_school",
"description": "Marie Curie",
"status": "draft",
"application_start_at": new Date(Date.now()),
"application_end_at": new Date(Date.now()),
"slots_available": 9,
"stipend_amount": 3.58,
// type code here for "files" field
},
{
"name": "Ada Lovelace",
"code": "Marie Curie",
// type code here for "relation_one" field
"education_level": "high_school",
"description": "Ada Lovelace",
"status": "open",
"application_start_at": new Date(Date.now()),
"application_end_at": new Date(Date.now()),
"slots_available": 9,
"stipend_amount": 3.06,
// type code here for "files" field
},
{
"name": "Alan Turing",
"code": "Marie Curie",
// type code here for "relation_one" field
"education_level": "college",
"description": "Grace Hopper",
"status": "closed",
"application_start_at": new Date(Date.now()),
"application_end_at": new Date(Date.now()),
"slots_available": 2,
"stipend_amount": 7.49,
// type code here for "files" field
},
{
"name": "Grace Hopper",
"code": "Marie Curie",
// type code here for "relation_one" field
"education_level": "high_school",
"description": "Grace Hopper",
"status": "open",
"application_start_at": new Date(Date.now()),
"application_end_at": new Date(Date.now()),
"slots_available": 5,
"stipend_amount": 7.32,
// type code here for "files" field
},
];
const SchoolsData = [
{
"name": "Marie Curie",
"school_level": "college",
"address": "Ada Lovelace",
"region": "Alan Turing",
"province": "Marie Curie",
"city": "Marie Curie",
"contact_email": "Grace Hopper",
"contact_phone": "Ada Lovelace",
},
{
"name": "Ada Lovelace",
"school_level": "high_school",
"address": "Grace Hopper",
"region": "Alan Turing",
"province": "Marie Curie",
"city": "Ada Lovelace",
"contact_email": "Ada Lovelace",
"contact_phone": "Ada Lovelace",
},
{
"name": "Grace Hopper",
"school_level": "high_school",
"address": "Marie Curie",
"region": "Alan Turing",
"province": "Marie Curie",
"city": "Ada Lovelace",
"contact_email": "Marie Curie",
"contact_phone": "Grace Hopper",
},
{
"name": "Alan Turing",
"school_level": "university",
"address": "Alan Turing",
"region": "Grace Hopper",
"province": "Alan Turing",
"city": "Alan Turing",
"contact_email": "Alan Turing",
"contact_phone": "Ada Lovelace",
},
];
const ScholarsData = [
{
"learner_reference_number": "Marie Curie",
"first_name": "Marie Curie",
"middle_name": "Alan Turing",
"last_name": "Alan Turing",
"education_level": "college",
// type code here for "relation_one" field
"grade_or_year_level": "Marie Curie",
"course_or_track": "Alan Turing",
"birth_date": new Date(Date.now()),
"gender": "prefer_not_to_say",
"email": "Alan Turing",
"phone_number": "Alan Turing",
"address": "Grace Hopper",
// type code here for "images" field
"active": false,
},
{
"learner_reference_number": "Grace Hopper",
"first_name": "Marie Curie",
"middle_name": "Marie Curie",
"last_name": "Ada Lovelace",
"education_level": "college",
// type code here for "relation_one" field
"grade_or_year_level": "Grace Hopper",
"course_or_track": "Alan Turing",
"birth_date": new Date(Date.now()),
"gender": "male",
"email": "Marie Curie",
"phone_number": "Grace Hopper",
"address": "Marie Curie",
// type code here for "images" field
"active": false,
},
{
"learner_reference_number": "Grace Hopper",
"first_name": "Alan Turing",
"middle_name": "Ada Lovelace",
"last_name": "Ada Lovelace",
"education_level": "high_school",
// type code here for "relation_one" field
"grade_or_year_level": "Alan Turing",
"course_or_track": "Marie Curie",
"birth_date": new Date(Date.now()),
"gender": "prefer_not_to_say",
"email": "Ada Lovelace",
"phone_number": "Grace Hopper",
"address": "Alan Turing",
// type code here for "images" field
"active": true,
},
{
"learner_reference_number": "Alan Turing",
"first_name": "Alan Turing",
"middle_name": "Ada Lovelace",
"last_name": "Ada Lovelace",
"education_level": "college",
// type code here for "relation_one" field
"grade_or_year_level": "Alan Turing",
"course_or_track": "Grace Hopper",
"birth_date": new Date(Date.now()),
"gender": "female",
"email": "Marie Curie",
"phone_number": "Alan Turing",
"address": "Marie Curie",
// type code here for "images" field
"active": true,
},
];
const ApplicationsData = [
{
"application_number": "Ada Lovelace",
// type code here for "relation_one" field
// type code here for "relation_one" field
"submitted_at": new Date(Date.now()),
"status": "draft",
"review_priority": "low",
"gwa_or_gpa": 2.01,
"remarks": "Alan Turing",
// type code here for "files" field
},
{
"application_number": "Grace Hopper",
// type code here for "relation_one" field
// type code here for "relation_one" field
"submitted_at": new Date(Date.now()),
"status": "withdrawn",
"review_priority": "low",
"gwa_or_gpa": 6.33,
"remarks": "Ada Lovelace",
// type code here for "files" field
},
{
"application_number": "Alan Turing",
// type code here for "relation_one" field
// type code here for "relation_one" field
"submitted_at": new Date(Date.now()),
"status": "rejected",
"review_priority": "normal",
"gwa_or_gpa": 2.62,
"remarks": "Alan Turing",
// type code here for "files" field
},
{
"application_number": "Marie Curie",
// type code here for "relation_one" field
// type code here for "relation_one" field
"submitted_at": new Date(Date.now()),
"status": "approved",
"review_priority": "normal",
"gwa_or_gpa": 3.51,
"remarks": "Alan Turing",
// type code here for "files" field
},
];
const ApplicationReviewsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"reviewed_at": new Date(Date.now()),
"decision": "needs_more_info",
"score": 9.58,
"notes": "Alan Turing",
// type code here for "files" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"reviewed_at": new Date(Date.now()),
"decision": "needs_more_info",
"score": 9.25,
"notes": "Ada Lovelace",
// type code here for "files" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"reviewed_at": new Date(Date.now()),
"decision": "needs_more_info",
"score": 3.53,
"notes": "Marie Curie",
// type code here for "files" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"reviewed_at": new Date(Date.now()),
"decision": "recommended_reject",
"score": 7.66,
"notes": "Ada Lovelace",
// type code here for "files" field
},
];
const ScholarAwardsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"awarded_at": new Date(Date.now()),
"effective_start_at": new Date(Date.now()),
"effective_end_at": new Date(Date.now()),
"award_status": "revoked",
"approved_amount": 5.82,
"award_notes": "Ada Lovelace",
// type code here for "files" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"awarded_at": new Date(Date.now()),
"effective_start_at": new Date(Date.now()),
"effective_end_at": new Date(Date.now()),
"award_status": "suspended",
"approved_amount": 1.79,
"award_notes": "Alan Turing",
// type code here for "files" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"awarded_at": new Date(Date.now()),
"effective_start_at": new Date(Date.now()),
"effective_end_at": new Date(Date.now()),
"award_status": "completed",
"approved_amount": 8.68,
"award_notes": "Ada Lovelace",
// type code here for "files" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"awarded_at": new Date(Date.now()),
"effective_start_at": new Date(Date.now()),
"effective_end_at": new Date(Date.now()),
"award_status": "revoked",
"approved_amount": 8.08,
"award_notes": "Alan Turing",
// type code here for "files" field
},
];
const DashboardTilesData = [
{
"title": "Marie Curie",
"subtitle": "Ada Lovelace",
"tile_type": "custom",
"education_level_filter": "high_school",
"status_filter": "all",
"sort_order": 6,
"active": false,
},
{
"title": "Ada Lovelace",
"subtitle": "Alan Turing",
"tile_type": "custom",
"education_level_filter": "high_school",
"status_filter": "submitted",
"sort_order": 1,
"active": true,
},
{
"title": "Marie Curie",
"subtitle": "Marie Curie",
"tile_type": "award_count",
"education_level_filter": "college",
"status_filter": "rejected",
"sort_order": 3,
"active": false,
},
{
"title": "Alan Turing",
"subtitle": "Grace Hopper",
"tile_type": "scholar_count",
"education_level_filter": "college",
"status_filter": "submitted",
"sort_order": 1,
"active": false,
},
];
// Similar logic for "relation_many"
async function associateScholarshipWithScholarship_type() {
const relatedScholarship_type0 = await ScholarshipTypes.findOne({
offset: Math.floor(Math.random() * (await ScholarshipTypes.count())),
});
const Scholarship0 = await Scholarships.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Scholarship0?.setScholarship_type)
{
await
Scholarship0.
setScholarship_type(relatedScholarship_type0);
}
const relatedScholarship_type1 = await ScholarshipTypes.findOne({
offset: Math.floor(Math.random() * (await ScholarshipTypes.count())),
});
const Scholarship1 = await Scholarships.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Scholarship1?.setScholarship_type)
{
await
Scholarship1.
setScholarship_type(relatedScholarship_type1);
}
const relatedScholarship_type2 = await ScholarshipTypes.findOne({
offset: Math.floor(Math.random() * (await ScholarshipTypes.count())),
});
const Scholarship2 = await Scholarships.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Scholarship2?.setScholarship_type)
{
await
Scholarship2.
setScholarship_type(relatedScholarship_type2);
}
const relatedScholarship_type3 = await ScholarshipTypes.findOne({
offset: Math.floor(Math.random() * (await ScholarshipTypes.count())),
});
const Scholarship3 = await Scholarships.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Scholarship3?.setScholarship_type)
{
await
Scholarship3.
setScholarship_type(relatedScholarship_type3);
}
}
async function associateScholarWithSchool() {
const relatedSchool0 = await Schools.findOne({
offset: Math.floor(Math.random() * (await Schools.count())),
});
const Scholar0 = await Scholars.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Scholar0?.setSchool)
{
await
Scholar0.
setSchool(relatedSchool0);
}
const relatedSchool1 = await Schools.findOne({
offset: Math.floor(Math.random() * (await Schools.count())),
});
const Scholar1 = await Scholars.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Scholar1?.setSchool)
{
await
Scholar1.
setSchool(relatedSchool1);
}
const relatedSchool2 = await Schools.findOne({
offset: Math.floor(Math.random() * (await Schools.count())),
});
const Scholar2 = await Scholars.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Scholar2?.setSchool)
{
await
Scholar2.
setSchool(relatedSchool2);
}
const relatedSchool3 = await Schools.findOne({
offset: Math.floor(Math.random() * (await Schools.count())),
});
const Scholar3 = await Scholars.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Scholar3?.setSchool)
{
await
Scholar3.
setSchool(relatedSchool3);
}
}
async function associateApplicationWithScholarship() {
const relatedScholarship0 = await Scholarships.findOne({
offset: Math.floor(Math.random() * (await Scholarships.count())),
});
const Application0 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Application0?.setScholarship)
{
await
Application0.
setScholarship(relatedScholarship0);
}
const relatedScholarship1 = await Scholarships.findOne({
offset: Math.floor(Math.random() * (await Scholarships.count())),
});
const Application1 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Application1?.setScholarship)
{
await
Application1.
setScholarship(relatedScholarship1);
}
const relatedScholarship2 = await Scholarships.findOne({
offset: Math.floor(Math.random() * (await Scholarships.count())),
});
const Application2 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Application2?.setScholarship)
{
await
Application2.
setScholarship(relatedScholarship2);
}
const relatedScholarship3 = await Scholarships.findOne({
offset: Math.floor(Math.random() * (await Scholarships.count())),
});
const Application3 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Application3?.setScholarship)
{
await
Application3.
setScholarship(relatedScholarship3);
}
}
async function associateApplicationWithScholar() {
const relatedScholar0 = await Scholars.findOne({
offset: Math.floor(Math.random() * (await Scholars.count())),
});
const Application0 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Application0?.setScholar)
{
await
Application0.
setScholar(relatedScholar0);
}
const relatedScholar1 = await Scholars.findOne({
offset: Math.floor(Math.random() * (await Scholars.count())),
});
const Application1 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Application1?.setScholar)
{
await
Application1.
setScholar(relatedScholar1);
}
const relatedScholar2 = await Scholars.findOne({
offset: Math.floor(Math.random() * (await Scholars.count())),
});
const Application2 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Application2?.setScholar)
{
await
Application2.
setScholar(relatedScholar2);
}
const relatedScholar3 = await Scholars.findOne({
offset: Math.floor(Math.random() * (await Scholars.count())),
});
const Application3 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Application3?.setScholar)
{
await
Application3.
setScholar(relatedScholar3);
}
}
async function associateApplicationReviewWithApplication() {
const relatedApplication0 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const ApplicationReview0 = await ApplicationReviews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ApplicationReview0?.setApplication)
{
await
ApplicationReview0.
setApplication(relatedApplication0);
}
const relatedApplication1 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const ApplicationReview1 = await ApplicationReviews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ApplicationReview1?.setApplication)
{
await
ApplicationReview1.
setApplication(relatedApplication1);
}
const relatedApplication2 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const ApplicationReview2 = await ApplicationReviews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ApplicationReview2?.setApplication)
{
await
ApplicationReview2.
setApplication(relatedApplication2);
}
const relatedApplication3 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const ApplicationReview3 = await ApplicationReviews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ApplicationReview3?.setApplication)
{
await
ApplicationReview3.
setApplication(relatedApplication3);
}
}
async function associateApplicationReviewWithReviewer() {
const relatedReviewer0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApplicationReview0 = await ApplicationReviews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ApplicationReview0?.setReviewer)
{
await
ApplicationReview0.
setReviewer(relatedReviewer0);
}
const relatedReviewer1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApplicationReview1 = await ApplicationReviews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ApplicationReview1?.setReviewer)
{
await
ApplicationReview1.
setReviewer(relatedReviewer1);
}
const relatedReviewer2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApplicationReview2 = await ApplicationReviews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ApplicationReview2?.setReviewer)
{
await
ApplicationReview2.
setReviewer(relatedReviewer2);
}
const relatedReviewer3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApplicationReview3 = await ApplicationReviews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ApplicationReview3?.setReviewer)
{
await
ApplicationReview3.
setReviewer(relatedReviewer3);
}
}
async function associateScholarAwardWithApplication() {
const relatedApplication0 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const ScholarAward0 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ScholarAward0?.setApplication)
{
await
ScholarAward0.
setApplication(relatedApplication0);
}
const relatedApplication1 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const ScholarAward1 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ScholarAward1?.setApplication)
{
await
ScholarAward1.
setApplication(relatedApplication1);
}
const relatedApplication2 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const ScholarAward2 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ScholarAward2?.setApplication)
{
await
ScholarAward2.
setApplication(relatedApplication2);
}
const relatedApplication3 = await Applications.findOne({
offset: Math.floor(Math.random() * (await Applications.count())),
});
const ScholarAward3 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ScholarAward3?.setApplication)
{
await
ScholarAward3.
setApplication(relatedApplication3);
}
}
async function associateScholarAwardWithScholar() {
const relatedScholar0 = await Scholars.findOne({
offset: Math.floor(Math.random() * (await Scholars.count())),
});
const ScholarAward0 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ScholarAward0?.setScholar)
{
await
ScholarAward0.
setScholar(relatedScholar0);
}
const relatedScholar1 = await Scholars.findOne({
offset: Math.floor(Math.random() * (await Scholars.count())),
});
const ScholarAward1 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ScholarAward1?.setScholar)
{
await
ScholarAward1.
setScholar(relatedScholar1);
}
const relatedScholar2 = await Scholars.findOne({
offset: Math.floor(Math.random() * (await Scholars.count())),
});
const ScholarAward2 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ScholarAward2?.setScholar)
{
await
ScholarAward2.
setScholar(relatedScholar2);
}
const relatedScholar3 = await Scholars.findOne({
offset: Math.floor(Math.random() * (await Scholars.count())),
});
const ScholarAward3 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ScholarAward3?.setScholar)
{
await
ScholarAward3.
setScholar(relatedScholar3);
}
}
async function associateScholarAwardWithScholarship() {
const relatedScholarship0 = await Scholarships.findOne({
offset: Math.floor(Math.random() * (await Scholarships.count())),
});
const ScholarAward0 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ScholarAward0?.setScholarship)
{
await
ScholarAward0.
setScholarship(relatedScholarship0);
}
const relatedScholarship1 = await Scholarships.findOne({
offset: Math.floor(Math.random() * (await Scholarships.count())),
});
const ScholarAward1 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ScholarAward1?.setScholarship)
{
await
ScholarAward1.
setScholarship(relatedScholarship1);
}
const relatedScholarship2 = await Scholarships.findOne({
offset: Math.floor(Math.random() * (await Scholarships.count())),
});
const ScholarAward2 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ScholarAward2?.setScholarship)
{
await
ScholarAward2.
setScholarship(relatedScholarship2);
}
const relatedScholarship3 = await Scholarships.findOne({
offset: Math.floor(Math.random() * (await Scholarships.count())),
});
const ScholarAward3 = await ScholarAwards.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ScholarAward3?.setScholarship)
{
await
ScholarAward3.
setScholarship(relatedScholarship3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await ScholarshipTypes.bulkCreate(ScholarshipTypesData);
await Scholarships.bulkCreate(ScholarshipsData);
await Schools.bulkCreate(SchoolsData);
await Scholars.bulkCreate(ScholarsData);
await Applications.bulkCreate(ApplicationsData);
await ApplicationReviews.bulkCreate(ApplicationReviewsData);
await ScholarAwards.bulkCreate(ScholarAwardsData);
await DashboardTiles.bulkCreate(DashboardTilesData);
await Promise.all([
// Similar logic for "relation_many"
await associateScholarshipWithScholarship_type(),
await associateScholarWithSchool(),
await associateApplicationWithScholarship(),
await associateApplicationWithScholar(),
await associateApplicationReviewWithApplication(),
await associateApplicationReviewWithReviewer(),
await associateScholarAwardWithApplication(),
await associateScholarAwardWithScholar(),
await associateScholarAwardWithScholarship(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('scholarship_types', null, {});
await queryInterface.bulkDelete('scholarships', null, {});
await queryInterface.bulkDelete('schools', null, {});
await queryInterface.bulkDelete('scholars', null, {});
await queryInterface.bulkDelete('applications', null, {});
await queryInterface.bulkDelete('application_reviews', null, {});
await queryInterface.bulkDelete('scholar_awards', null, {});
await queryInterface.bulkDelete('dashboard_tiles', null, {});
},
};