31912/backend/src/db/seeders/20231127130745-sample-data.js
2025-06-01 17:30:46 +00:00

1264 lines
30 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const AttendanceRecords = db.attendance_records;
const Classes = db.classes;
const Exceptions = db.exceptions;
const LeaveApplications = db.leave_applications;
const Timetables = db.timetables;
const Colleges = db.colleges;
const AttendanceRecordsData = [
{
// type code here for "relation_one" field
date: new Date('2023-10-01T08:00:00Z'),
check_in_time: new Date('2023-10-01T08:05:00Z'),
break_count: 1,
break_times: '08:30-08:35',
checkout_time: new Date('2023-10-01T09:00:00Z'),
status: 'Late',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date: new Date('2023-10-01T09:00:00Z'),
check_in_time: new Date('2023-10-01T09:10:00Z'),
break_count: 0,
break_times: '',
checkout_time: new Date('2023-10-01T10:00:00Z'),
status: 'Present',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date: new Date('2023-10-01T10:00:00Z'),
check_in_time: new Date('2023-10-01T10:00:00Z'),
break_count: 2,
break_times: '10:15-10:20,10:40-10:45',
checkout_time: new Date('2023-10-01T11:00:00Z'),
status: 'Absent',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date: new Date('2023-10-01T11:00:00Z'),
check_in_time: new Date('2023-10-01T11:05:00Z'),
break_count: 1,
break_times: '11:30-11:35',
checkout_time: new Date('2023-10-01T12:00:00Z'),
status: 'Absent',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date: new Date('2023-10-01T12:00:00Z'),
check_in_time: new Date('2023-10-01T12:10:00Z'),
break_count: 0,
break_times: '',
checkout_time: new Date('2023-10-01T13:00:00Z'),
status: 'Present',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const ClassesData = [
{
name: 'CS101',
qr_code: 'QR123',
boundary_area: 'Area1',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Math202',
qr_code: 'QR456',
boundary_area: 'Area2',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Physics101',
qr_code: 'QR789',
boundary_area: 'Area3',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Chemistry101',
qr_code: 'QR321',
boundary_area: 'Area4',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Biology101',
qr_code: 'QR654',
boundary_area: 'Area5',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ExceptionsData = [
{
type: 'Late',
// type code here for "relation_one" field
// type code here for "relation_one" field
reason: 'Traffic delay',
status: 'Pending',
approval_chain: 'Class Incharge -> HOD',
// type code here for "relation_one" field
},
{
type: 'Reject',
// type code here for "relation_one" field
// type code here for "relation_one" field
reason: 'Schedule conflict',
status: 'Approved',
approval_chain: 'HOD -> Dean',
// type code here for "relation_one" field
},
{
type: 'Swap',
// type code here for "relation_one" field
// type code here for "relation_one" field
reason: 'Left early',
status: 'Pending',
approval_chain: 'Teacher -> Class Incharge',
// type code here for "relation_one" field
},
{
type: 'Late',
// type code here for "relation_one" field
// type code here for "relation_one" field
reason: 'Medical emergency',
status: 'Rejected',
approval_chain: 'Class Incharge -> HOD',
// type code here for "relation_one" field
},
{
type: 'Reject',
// type code here for "relation_one" field
// type code here for "relation_one" field
reason: 'Personal reasons',
status: 'Pending',
approval_chain: 'HOD -> Dean',
// type code here for "relation_one" field
},
];
const LeaveApplicationsData = [
{
// type code here for "relation_one" field
date_from: new Date('2023-09-28T00:00:00Z'),
date_to: new Date('2023-09-29T00:00:00Z'),
reason: 'Family event',
status: 'Rejected',
applied_date: new Date('2023-09-25T00:00:00Z'),
approval_status: 'Approved',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date_from: new Date('2023-09-30T00:00:00Z'),
date_to: new Date('2023-10-01T00:00:00Z'),
reason: 'Medical leave',
status: 'Rejected',
applied_date: new Date('2023-09-28T00:00:00Z'),
approval_status: 'Pending',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date_from: new Date('2023-10-02T00:00:00Z'),
date_to: new Date('2023-10-03T00:00:00Z'),
reason: 'Conference attendance',
status: 'Approved',
applied_date: new Date('2023-09-29T00:00:00Z'),
approval_status: 'Approved',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date_from: new Date('2023-10-04T00:00:00Z'),
date_to: new Date('2023-10-05T00:00:00Z'),
reason: 'Personal reasons',
status: 'Pending',
applied_date: new Date('2023-09-30T00:00:00Z'),
approval_status: 'Pending',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date_from: new Date('2023-10-06T00:00:00Z'),
date_to: new Date('2023-10-07T00:00:00Z'),
reason: 'Family emergency',
status: 'Approved',
applied_date: new Date('2023-10-01T00:00:00Z'),
approval_status: 'Rejected',
// type code here for "relation_one" field
},
];
const TimetablesData = [
{
day: 'Saturday',
period: 1,
// type code here for "relation_one" field
start_time: new Date('2023-10-01T08:00:00Z'),
end_time: new Date('2023-10-01T09:00:00Z'),
// type code here for "relation_one" field
},
{
day: 'Wednesday',
period: 2,
// type code here for "relation_one" field
start_time: new Date('2023-10-01T09:00:00Z'),
end_time: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
day: 'Wednesday',
period: 3,
// type code here for "relation_one" field
start_time: new Date('2023-10-01T10:00:00Z'),
end_time: new Date('2023-10-01T11:00:00Z'),
// type code here for "relation_one" field
},
{
day: 'Wednesday',
period: 4,
// type code here for "relation_one" field
start_time: new Date('2023-10-01T11:00:00Z'),
end_time: new Date('2023-10-01T12:00:00Z'),
// type code here for "relation_one" field
},
{
day: 'Friday',
period: 5,
// type code here for "relation_one" field
start_time: new Date('2023-10-01T12:00:00Z'),
end_time: new Date('2023-10-01T13:00:00Z'),
// type code here for "relation_one" field
},
];
const CollegesData = [
{
name: 'City University',
},
{
name: 'Green Valley College',
},
{
name: 'Alexander Fleming',
},
{
name: 'Robert Koch',
},
{
name: 'William Herschel',
},
];
// Similar logic for "relation_many"
async function associateUserWithCollege() {
const relatedCollege0 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setCollege) {
await User0.setCollege(relatedCollege0);
}
const relatedCollege1 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setCollege) {
await User1.setCollege(relatedCollege1);
}
const relatedCollege2 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setCollege) {
await User2.setCollege(relatedCollege2);
}
const relatedCollege3 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setCollege) {
await User3.setCollege(relatedCollege3);
}
const relatedCollege4 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const User4 = await Users.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (User4?.setCollege) {
await User4.setCollege(relatedCollege4);
}
}
async function associateAttendanceRecordWithStudent() {
const relatedStudent0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AttendanceRecord0 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (AttendanceRecord0?.setStudent) {
await AttendanceRecord0.setStudent(relatedStudent0);
}
const relatedStudent1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AttendanceRecord1 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (AttendanceRecord1?.setStudent) {
await AttendanceRecord1.setStudent(relatedStudent1);
}
const relatedStudent2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AttendanceRecord2 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (AttendanceRecord2?.setStudent) {
await AttendanceRecord2.setStudent(relatedStudent2);
}
const relatedStudent3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AttendanceRecord3 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (AttendanceRecord3?.setStudent) {
await AttendanceRecord3.setStudent(relatedStudent3);
}
const relatedStudent4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AttendanceRecord4 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (AttendanceRecord4?.setStudent) {
await AttendanceRecord4.setStudent(relatedStudent4);
}
}
// Similar logic for "relation_many"
async function associateAttendanceRecordWithCollege() {
const relatedCollege0 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const AttendanceRecord0 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (AttendanceRecord0?.setCollege) {
await AttendanceRecord0.setCollege(relatedCollege0);
}
const relatedCollege1 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const AttendanceRecord1 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (AttendanceRecord1?.setCollege) {
await AttendanceRecord1.setCollege(relatedCollege1);
}
const relatedCollege2 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const AttendanceRecord2 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (AttendanceRecord2?.setCollege) {
await AttendanceRecord2.setCollege(relatedCollege2);
}
const relatedCollege3 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const AttendanceRecord3 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (AttendanceRecord3?.setCollege) {
await AttendanceRecord3.setCollege(relatedCollege3);
}
const relatedCollege4 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const AttendanceRecord4 = await AttendanceRecords.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (AttendanceRecord4?.setCollege) {
await AttendanceRecord4.setCollege(relatedCollege4);
}
}
async function associateClassWithTimetable() {
const relatedTimetable0 = await Timetables.findOne({
offset: Math.floor(Math.random() * (await Timetables.count())),
});
const Class0 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Class0?.setTimetable) {
await Class0.setTimetable(relatedTimetable0);
}
const relatedTimetable1 = await Timetables.findOne({
offset: Math.floor(Math.random() * (await Timetables.count())),
});
const Class1 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Class1?.setTimetable) {
await Class1.setTimetable(relatedTimetable1);
}
const relatedTimetable2 = await Timetables.findOne({
offset: Math.floor(Math.random() * (await Timetables.count())),
});
const Class2 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Class2?.setTimetable) {
await Class2.setTimetable(relatedTimetable2);
}
const relatedTimetable3 = await Timetables.findOne({
offset: Math.floor(Math.random() * (await Timetables.count())),
});
const Class3 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Class3?.setTimetable) {
await Class3.setTimetable(relatedTimetable3);
}
const relatedTimetable4 = await Timetables.findOne({
offset: Math.floor(Math.random() * (await Timetables.count())),
});
const Class4 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Class4?.setTimetable) {
await Class4.setTimetable(relatedTimetable4);
}
}
async function associateClassWithAssigned_teacher() {
const relatedAssigned_teacher0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Class0 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Class0?.setAssigned_teacher) {
await Class0.setAssigned_teacher(relatedAssigned_teacher0);
}
const relatedAssigned_teacher1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Class1 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Class1?.setAssigned_teacher) {
await Class1.setAssigned_teacher(relatedAssigned_teacher1);
}
const relatedAssigned_teacher2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Class2 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Class2?.setAssigned_teacher) {
await Class2.setAssigned_teacher(relatedAssigned_teacher2);
}
const relatedAssigned_teacher3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Class3 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Class3?.setAssigned_teacher) {
await Class3.setAssigned_teacher(relatedAssigned_teacher3);
}
const relatedAssigned_teacher4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Class4 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Class4?.setAssigned_teacher) {
await Class4.setAssigned_teacher(relatedAssigned_teacher4);
}
}
async function associateClassWithCollege() {
const relatedCollege0 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Class0 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Class0?.setCollege) {
await Class0.setCollege(relatedCollege0);
}
const relatedCollege1 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Class1 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Class1?.setCollege) {
await Class1.setCollege(relatedCollege1);
}
const relatedCollege2 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Class2 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Class2?.setCollege) {
await Class2.setCollege(relatedCollege2);
}
const relatedCollege3 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Class3 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Class3?.setCollege) {
await Class3.setCollege(relatedCollege3);
}
const relatedCollege4 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Class4 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Class4?.setCollege) {
await Class4.setCollege(relatedCollege4);
}
}
async function associateExceptionWithRaised_by() {
const relatedRaised_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception0 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Exception0?.setRaised_by) {
await Exception0.setRaised_by(relatedRaised_by0);
}
const relatedRaised_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception1 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Exception1?.setRaised_by) {
await Exception1.setRaised_by(relatedRaised_by1);
}
const relatedRaised_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception2 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Exception2?.setRaised_by) {
await Exception2.setRaised_by(relatedRaised_by2);
}
const relatedRaised_by3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception3 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Exception3?.setRaised_by) {
await Exception3.setRaised_by(relatedRaised_by3);
}
const relatedRaised_by4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception4 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Exception4?.setRaised_by) {
await Exception4.setRaised_by(relatedRaised_by4);
}
}
async function associateExceptionWithRaised_for() {
const relatedRaised_for0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception0 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Exception0?.setRaised_for) {
await Exception0.setRaised_for(relatedRaised_for0);
}
const relatedRaised_for1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception1 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Exception1?.setRaised_for) {
await Exception1.setRaised_for(relatedRaised_for1);
}
const relatedRaised_for2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception2 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Exception2?.setRaised_for) {
await Exception2.setRaised_for(relatedRaised_for2);
}
const relatedRaised_for3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception3 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Exception3?.setRaised_for) {
await Exception3.setRaised_for(relatedRaised_for3);
}
const relatedRaised_for4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Exception4 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Exception4?.setRaised_for) {
await Exception4.setRaised_for(relatedRaised_for4);
}
}
async function associateExceptionWithCollege() {
const relatedCollege0 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Exception0 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Exception0?.setCollege) {
await Exception0.setCollege(relatedCollege0);
}
const relatedCollege1 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Exception1 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Exception1?.setCollege) {
await Exception1.setCollege(relatedCollege1);
}
const relatedCollege2 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Exception2 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Exception2?.setCollege) {
await Exception2.setCollege(relatedCollege2);
}
const relatedCollege3 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Exception3 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Exception3?.setCollege) {
await Exception3.setCollege(relatedCollege3);
}
const relatedCollege4 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Exception4 = await Exceptions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Exception4?.setCollege) {
await Exception4.setCollege(relatedCollege4);
}
}
async function associateLeaveApplicationWithStudent() {
const relatedStudent0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const LeaveApplication0 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (LeaveApplication0?.setStudent) {
await LeaveApplication0.setStudent(relatedStudent0);
}
const relatedStudent1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const LeaveApplication1 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (LeaveApplication1?.setStudent) {
await LeaveApplication1.setStudent(relatedStudent1);
}
const relatedStudent2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const LeaveApplication2 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (LeaveApplication2?.setStudent) {
await LeaveApplication2.setStudent(relatedStudent2);
}
const relatedStudent3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const LeaveApplication3 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (LeaveApplication3?.setStudent) {
await LeaveApplication3.setStudent(relatedStudent3);
}
const relatedStudent4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const LeaveApplication4 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (LeaveApplication4?.setStudent) {
await LeaveApplication4.setStudent(relatedStudent4);
}
}
async function associateLeaveApplicationWithCollege() {
const relatedCollege0 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const LeaveApplication0 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (LeaveApplication0?.setCollege) {
await LeaveApplication0.setCollege(relatedCollege0);
}
const relatedCollege1 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const LeaveApplication1 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (LeaveApplication1?.setCollege) {
await LeaveApplication1.setCollege(relatedCollege1);
}
const relatedCollege2 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const LeaveApplication2 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (LeaveApplication2?.setCollege) {
await LeaveApplication2.setCollege(relatedCollege2);
}
const relatedCollege3 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const LeaveApplication3 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (LeaveApplication3?.setCollege) {
await LeaveApplication3.setCollege(relatedCollege3);
}
const relatedCollege4 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const LeaveApplication4 = await LeaveApplications.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (LeaveApplication4?.setCollege) {
await LeaveApplication4.setCollege(relatedCollege4);
}
}
async function associateTimetableWithTeacher() {
const relatedTeacher0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Timetable0 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Timetable0?.setTeacher) {
await Timetable0.setTeacher(relatedTeacher0);
}
const relatedTeacher1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Timetable1 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Timetable1?.setTeacher) {
await Timetable1.setTeacher(relatedTeacher1);
}
const relatedTeacher2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Timetable2 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Timetable2?.setTeacher) {
await Timetable2.setTeacher(relatedTeacher2);
}
const relatedTeacher3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Timetable3 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Timetable3?.setTeacher) {
await Timetable3.setTeacher(relatedTeacher3);
}
const relatedTeacher4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Timetable4 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Timetable4?.setTeacher) {
await Timetable4.setTeacher(relatedTeacher4);
}
}
async function associateTimetableWithCollege() {
const relatedCollege0 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Timetable0 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Timetable0?.setCollege) {
await Timetable0.setCollege(relatedCollege0);
}
const relatedCollege1 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Timetable1 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Timetable1?.setCollege) {
await Timetable1.setCollege(relatedCollege1);
}
const relatedCollege2 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Timetable2 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Timetable2?.setCollege) {
await Timetable2.setCollege(relatedCollege2);
}
const relatedCollege3 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Timetable3 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Timetable3?.setCollege) {
await Timetable3.setCollege(relatedCollege3);
}
const relatedCollege4 = await Colleges.findOne({
offset: Math.floor(Math.random() * (await Colleges.count())),
});
const Timetable4 = await Timetables.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Timetable4?.setCollege) {
await Timetable4.setCollege(relatedCollege4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await AttendanceRecords.bulkCreate(AttendanceRecordsData);
await Classes.bulkCreate(ClassesData);
await Exceptions.bulkCreate(ExceptionsData);
await LeaveApplications.bulkCreate(LeaveApplicationsData);
await Timetables.bulkCreate(TimetablesData);
await Colleges.bulkCreate(CollegesData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithCollege(),
await associateAttendanceRecordWithStudent(),
// Similar logic for "relation_many"
await associateAttendanceRecordWithCollege(),
await associateClassWithTimetable(),
await associateClassWithAssigned_teacher(),
await associateClassWithCollege(),
await associateExceptionWithRaised_by(),
await associateExceptionWithRaised_for(),
await associateExceptionWithCollege(),
await associateLeaveApplicationWithStudent(),
await associateLeaveApplicationWithCollege(),
await associateTimetableWithTeacher(),
await associateTimetableWithCollege(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('attendance_records', null, {});
await queryInterface.bulkDelete('classes', null, {});
await queryInterface.bulkDelete('exceptions', null, {});
await queryInterface.bulkDelete('leave_applications', null, {});
await queryInterface.bulkDelete('timetables', null, {});
await queryInterface.bulkDelete('colleges', null, {});
},
};