1111 lines
26 KiB
JavaScript
1111 lines
26 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const AdminSettings = db.admin_settings;
|
|
|
|
const AdmitCards = db.admit_cards;
|
|
|
|
const Classes = db.classes;
|
|
|
|
const Finances = db.finances;
|
|
|
|
const PeriodRoutines = db.period_routines;
|
|
|
|
const Results = db.results;
|
|
|
|
const Students = db.students;
|
|
|
|
const Teachers = db.teachers;
|
|
|
|
const Templates = db.templates;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const AdminSettingsData = [
|
|
{
|
|
setting_name: 'Language',
|
|
|
|
value: 'English',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
setting_name: 'Currency',
|
|
|
|
value: 'BDT',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
setting_name: 'TimeZone',
|
|
|
|
value: 'Asia/Dhaka',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
setting_name: 'DateFormat',
|
|
|
|
value: 'DD-MM-YYYY',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const AdmitCardsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
issue_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
issue_date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
issue_date: new Date('2023-10-03T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
issue_date: new Date('2023-10-04T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ClassesData = [
|
|
{
|
|
name: 'Class 1',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Class 2',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Class 3',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Class 4',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const FinancesData = [
|
|
{
|
|
amount: 5000,
|
|
|
|
description: 'Monthly Tuition Fee',
|
|
|
|
date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 1500,
|
|
|
|
description: 'Library Fee',
|
|
|
|
date: new Date('2023-10-02T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 2000,
|
|
|
|
description: 'Sports Fee',
|
|
|
|
date: new Date('2023-10-03T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 3000,
|
|
|
|
description: 'Lab Fee',
|
|
|
|
date: new Date('2023-10-04T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PeriodRoutinesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
day: 'Monday',
|
|
|
|
time_slot: '09:00-10:00',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
day: 'Tuesday',
|
|
|
|
time_slot: '10:00-11:00',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
day: 'Wednesday',
|
|
|
|
time_slot: '11:00-12:00',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
day: 'Thursday',
|
|
|
|
time_slot: '12:00-13:00',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ResultsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
marks: 85.5,
|
|
|
|
subject: 'Mathematics',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
marks: 78,
|
|
|
|
subject: 'Science',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
marks: 92,
|
|
|
|
subject: 'English',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
marks: 88.5,
|
|
|
|
subject: 'History',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const StudentsData = [
|
|
{
|
|
first_name: 'Ayesha',
|
|
|
|
last_name: 'Rahman',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Karim',
|
|
|
|
last_name: 'Ahmed',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Fatima',
|
|
|
|
last_name: 'Khan',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Rafiq',
|
|
|
|
last_name: 'Hossain',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TeachersData = [
|
|
{
|
|
first_name: 'Anwar',
|
|
|
|
last_name: 'Hossain',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Sadia',
|
|
|
|
last_name: 'Begum',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Jamil',
|
|
|
|
last_name: 'Khan',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Nadia',
|
|
|
|
last_name: 'Rahman',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TemplatesData = [
|
|
{
|
|
name: 'Admit Card Template',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Class Routine Template',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'ID Card Template',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Marksheet Template',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Ernst Mayr',
|
|
},
|
|
|
|
{
|
|
name: 'Ernst Haeckel',
|
|
},
|
|
|
|
{
|
|
name: 'James Clerk Maxwell',
|
|
},
|
|
|
|
{
|
|
name: 'Justus Liebig',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setOrganization) {
|
|
await User0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setOrganization) {
|
|
await User1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setOrganization) {
|
|
await User2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setOrganization) {
|
|
await User3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateAdminSettingWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const AdminSetting0 = await AdminSettings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (AdminSetting0?.setOrganization) {
|
|
await AdminSetting0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const AdminSetting1 = await AdminSettings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (AdminSetting1?.setOrganization) {
|
|
await AdminSetting1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const AdminSetting2 = await AdminSettings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (AdminSetting2?.setOrganization) {
|
|
await AdminSetting2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const AdminSetting3 = await AdminSettings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (AdminSetting3?.setOrganization) {
|
|
await AdminSetting3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateAdmitCardWithStudent() {
|
|
const relatedStudent0 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const AdmitCard0 = await AdmitCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (AdmitCard0?.setStudent) {
|
|
await AdmitCard0.setStudent(relatedStudent0);
|
|
}
|
|
|
|
const relatedStudent1 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const AdmitCard1 = await AdmitCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (AdmitCard1?.setStudent) {
|
|
await AdmitCard1.setStudent(relatedStudent1);
|
|
}
|
|
|
|
const relatedStudent2 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const AdmitCard2 = await AdmitCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (AdmitCard2?.setStudent) {
|
|
await AdmitCard2.setStudent(relatedStudent2);
|
|
}
|
|
|
|
const relatedStudent3 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const AdmitCard3 = await AdmitCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (AdmitCard3?.setStudent) {
|
|
await AdmitCard3.setStudent(relatedStudent3);
|
|
}
|
|
}
|
|
|
|
async function associateAdmitCardWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const AdmitCard0 = await AdmitCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (AdmitCard0?.setOrganization) {
|
|
await AdmitCard0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const AdmitCard1 = await AdmitCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (AdmitCard1?.setOrganization) {
|
|
await AdmitCard1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const AdmitCard2 = await AdmitCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (AdmitCard2?.setOrganization) {
|
|
await AdmitCard2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const AdmitCard3 = await AdmitCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (AdmitCard3?.setOrganization) {
|
|
await AdmitCard3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateClassWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Class0 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Class0?.setOrganization) {
|
|
await Class0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Class1 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Class1?.setOrganization) {
|
|
await Class1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Class2 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Class2?.setOrganization) {
|
|
await Class2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Class3 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Class3?.setOrganization) {
|
|
await Class3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateFinanceWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Finance0 = await Finances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Finance0?.setOrganization) {
|
|
await Finance0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Finance1 = await Finances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Finance1?.setOrganization) {
|
|
await Finance1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Finance2 = await Finances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Finance2?.setOrganization) {
|
|
await Finance2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Finance3 = await Finances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Finance3?.setOrganization) {
|
|
await Finance3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associatePeriodRoutineWithTeacher() {
|
|
const relatedTeacher0 = await Teachers.findOne({
|
|
offset: Math.floor(Math.random() * (await Teachers.count())),
|
|
});
|
|
const PeriodRoutine0 = await PeriodRoutines.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (PeriodRoutine0?.setTeacher) {
|
|
await PeriodRoutine0.setTeacher(relatedTeacher0);
|
|
}
|
|
|
|
const relatedTeacher1 = await Teachers.findOne({
|
|
offset: Math.floor(Math.random() * (await Teachers.count())),
|
|
});
|
|
const PeriodRoutine1 = await PeriodRoutines.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (PeriodRoutine1?.setTeacher) {
|
|
await PeriodRoutine1.setTeacher(relatedTeacher1);
|
|
}
|
|
|
|
const relatedTeacher2 = await Teachers.findOne({
|
|
offset: Math.floor(Math.random() * (await Teachers.count())),
|
|
});
|
|
const PeriodRoutine2 = await PeriodRoutines.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (PeriodRoutine2?.setTeacher) {
|
|
await PeriodRoutine2.setTeacher(relatedTeacher2);
|
|
}
|
|
|
|
const relatedTeacher3 = await Teachers.findOne({
|
|
offset: Math.floor(Math.random() * (await Teachers.count())),
|
|
});
|
|
const PeriodRoutine3 = await PeriodRoutines.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (PeriodRoutine3?.setTeacher) {
|
|
await PeriodRoutine3.setTeacher(relatedTeacher3);
|
|
}
|
|
}
|
|
|
|
async function associatePeriodRoutineWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const PeriodRoutine0 = await PeriodRoutines.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (PeriodRoutine0?.setOrganization) {
|
|
await PeriodRoutine0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const PeriodRoutine1 = await PeriodRoutines.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (PeriodRoutine1?.setOrganization) {
|
|
await PeriodRoutine1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const PeriodRoutine2 = await PeriodRoutines.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (PeriodRoutine2?.setOrganization) {
|
|
await PeriodRoutine2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const PeriodRoutine3 = await PeriodRoutines.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (PeriodRoutine3?.setOrganization) {
|
|
await PeriodRoutine3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateResultWithStudent() {
|
|
const relatedStudent0 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Result0 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Result0?.setStudent) {
|
|
await Result0.setStudent(relatedStudent0);
|
|
}
|
|
|
|
const relatedStudent1 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Result1 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Result1?.setStudent) {
|
|
await Result1.setStudent(relatedStudent1);
|
|
}
|
|
|
|
const relatedStudent2 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Result2 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Result2?.setStudent) {
|
|
await Result2.setStudent(relatedStudent2);
|
|
}
|
|
|
|
const relatedStudent3 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Result3 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Result3?.setStudent) {
|
|
await Result3.setStudent(relatedStudent3);
|
|
}
|
|
}
|
|
|
|
async function associateResultWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Result0 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Result0?.setOrganization) {
|
|
await Result0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Result1 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Result1?.setOrganization) {
|
|
await Result1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Result2 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Result2?.setOrganization) {
|
|
await Result2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Result3 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Result3?.setOrganization) {
|
|
await Result3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateStudentWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Student0 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Student0?.setOrganization) {
|
|
await Student0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Student1 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Student1?.setOrganization) {
|
|
await Student1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Student2 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Student2?.setOrganization) {
|
|
await Student2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Student3 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Student3?.setOrganization) {
|
|
await Student3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateTeacherWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Teacher0 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Teacher0?.setOrganization) {
|
|
await Teacher0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Teacher1 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Teacher1?.setOrganization) {
|
|
await Teacher1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Teacher2 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Teacher2?.setOrganization) {
|
|
await Teacher2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Teacher3 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Teacher3?.setOrganization) {
|
|
await Teacher3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateTemplateWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Template0 = await Templates.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Template0?.setOrganization) {
|
|
await Template0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Template1 = await Templates.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Template1?.setOrganization) {
|
|
await Template1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Template2 = await Templates.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Template2?.setOrganization) {
|
|
await Template2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Template3 = await Templates.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Template3?.setOrganization) {
|
|
await Template3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await AdminSettings.bulkCreate(AdminSettingsData);
|
|
|
|
await AdmitCards.bulkCreate(AdmitCardsData);
|
|
|
|
await Classes.bulkCreate(ClassesData);
|
|
|
|
await Finances.bulkCreate(FinancesData);
|
|
|
|
await PeriodRoutines.bulkCreate(PeriodRoutinesData);
|
|
|
|
await Results.bulkCreate(ResultsData);
|
|
|
|
await Students.bulkCreate(StudentsData);
|
|
|
|
await Teachers.bulkCreate(TeachersData);
|
|
|
|
await Templates.bulkCreate(TemplatesData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateAdminSettingWithOrganization(),
|
|
|
|
await associateAdmitCardWithStudent(),
|
|
|
|
await associateAdmitCardWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateClassWithOrganization(),
|
|
|
|
await associateFinanceWithOrganization(),
|
|
|
|
await associatePeriodRoutineWithTeacher(),
|
|
|
|
await associatePeriodRoutineWithOrganization(),
|
|
|
|
await associateResultWithStudent(),
|
|
|
|
await associateResultWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateStudentWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateTeacherWithOrganization(),
|
|
|
|
await associateTemplateWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('admin_settings', null, {});
|
|
|
|
await queryInterface.bulkDelete('admit_cards', null, {});
|
|
|
|
await queryInterface.bulkDelete('classes', null, {});
|
|
|
|
await queryInterface.bulkDelete('finances', null, {});
|
|
|
|
await queryInterface.bulkDelete('period_routines', null, {});
|
|
|
|
await queryInterface.bulkDelete('results', null, {});
|
|
|
|
await queryInterface.bulkDelete('students', null, {});
|
|
|
|
await queryInterface.bulkDelete('teachers', null, {});
|
|
|
|
await queryInterface.bulkDelete('templates', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|