947 lines
22 KiB
JavaScript
947 lines
22 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Announcements = db.announcements;
|
|
|
|
const AttendanceRecords = db.attendance_records;
|
|
|
|
const Classes = db.classes;
|
|
|
|
const Grades = db.grades;
|
|
|
|
const Invoices = db.invoices;
|
|
|
|
const Subjects = db.subjects;
|
|
|
|
const Schools = db.schools;
|
|
|
|
const AnnouncementsData = [
|
|
{
|
|
title: 'Welcome Back!',
|
|
|
|
content: 'We are excited to start the new school year!',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
date: new Date('2023-09-01T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Parent-Teacher Meeting',
|
|
|
|
content: 'Join us for the upcoming parent-teacher meeting.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
date: new Date('2023-09-15T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'School Picnic',
|
|
|
|
content: "Don't forget to sign up for the school picnic!",
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
date: new Date('2023-09-20T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Exam Schedule',
|
|
|
|
content: 'The exam schedule has been released.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
date: new Date('2023-10-01T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const AttendanceRecordsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2023-10-01T08:00:00Z'),
|
|
|
|
present: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2023-10-01T08:00:00Z'),
|
|
|
|
present: false,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
present: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
present: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ClassesData = [
|
|
{
|
|
name: 'Math 101',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Science 201',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'History 301',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Art 101',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const GradesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
grade: 85.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
grade: 78,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
grade: 92,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
grade: 88.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const InvoicesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 500,
|
|
|
|
status: 'Overdue',
|
|
|
|
due_date: new Date('2023-10-15T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 300,
|
|
|
|
status: 'Overdue',
|
|
|
|
due_date: new Date('2023-09-15T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 450,
|
|
|
|
status: 'Pending',
|
|
|
|
due_date: new Date('2023-09-01T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 600,
|
|
|
|
status: 'Pending',
|
|
|
|
due_date: new Date('2023-11-01T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SubjectsData = [
|
|
{
|
|
name: 'Mathematics',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Science',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'History',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Art',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SchoolsData = [
|
|
{
|
|
name: 'Greenwood High',
|
|
},
|
|
|
|
{
|
|
name: 'Riverside Academy',
|
|
},
|
|
|
|
{
|
|
name: 'Sunnydale School',
|
|
},
|
|
|
|
{
|
|
name: 'Hilltop Institute',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setSchool) {
|
|
await User0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setSchool) {
|
|
await User1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setSchool) {
|
|
await User2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setSchool) {
|
|
await User3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateAnnouncementWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Announcement0 = await Announcements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Announcement0?.setSchool) {
|
|
await Announcement0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Announcement1 = await Announcements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Announcement1?.setSchool) {
|
|
await Announcement1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Announcement2 = await Announcements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Announcement2?.setSchool) {
|
|
await Announcement2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Announcement3 = await Announcements.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Announcement3?.setSchool) {
|
|
await Announcement3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
async function associateAttendanceRecordWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const AttendanceRecord0 = await AttendanceRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (AttendanceRecord0?.setSchool) {
|
|
await AttendanceRecord0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const AttendanceRecord1 = await AttendanceRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (AttendanceRecord1?.setSchool) {
|
|
await AttendanceRecord1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const AttendanceRecord2 = await AttendanceRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (AttendanceRecord2?.setSchool) {
|
|
await AttendanceRecord2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const AttendanceRecord3 = await AttendanceRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (AttendanceRecord3?.setSchool) {
|
|
await AttendanceRecord3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateClassWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class0 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Class0?.setSchool) {
|
|
await Class0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class1 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Class1?.setSchool) {
|
|
await Class1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class2 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Class2?.setSchool) {
|
|
await Class2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class3 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Class3?.setSchool) {
|
|
await Class3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateClassWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class0 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Class0?.setSchool) {
|
|
await Class0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class1 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Class1?.setSchool) {
|
|
await Class1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class2 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Class2?.setSchool) {
|
|
await Class2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class3 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Class3?.setSchool) {
|
|
await Class3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateGradeWithStudent() {
|
|
const relatedStudent0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Grade0 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Grade0?.setStudent) {
|
|
await Grade0.setStudent(relatedStudent0);
|
|
}
|
|
|
|
const relatedStudent1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Grade1 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Grade1?.setStudent) {
|
|
await Grade1.setStudent(relatedStudent1);
|
|
}
|
|
|
|
const relatedStudent2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Grade2 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Grade2?.setStudent) {
|
|
await Grade2.setStudent(relatedStudent2);
|
|
}
|
|
|
|
const relatedStudent3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Grade3 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Grade3?.setStudent) {
|
|
await Grade3.setStudent(relatedStudent3);
|
|
}
|
|
}
|
|
|
|
async function associateGradeWithSubject() {
|
|
const relatedSubject0 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Grade0 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Grade0?.setSubject) {
|
|
await Grade0.setSubject(relatedSubject0);
|
|
}
|
|
|
|
const relatedSubject1 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Grade1 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Grade1?.setSubject) {
|
|
await Grade1.setSubject(relatedSubject1);
|
|
}
|
|
|
|
const relatedSubject2 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Grade2 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Grade2?.setSubject) {
|
|
await Grade2.setSubject(relatedSubject2);
|
|
}
|
|
|
|
const relatedSubject3 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Grade3 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Grade3?.setSubject) {
|
|
await Grade3.setSubject(relatedSubject3);
|
|
}
|
|
}
|
|
|
|
async function associateGradeWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Grade0 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Grade0?.setSchool) {
|
|
await Grade0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Grade1 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Grade1?.setSchool) {
|
|
await Grade1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Grade2 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Grade2?.setSchool) {
|
|
await Grade2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Grade3 = await Grades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Grade3?.setSchool) {
|
|
await Grade3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateInvoiceWithParent() {
|
|
const relatedParent0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Invoice0 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Invoice0?.setParent) {
|
|
await Invoice0.setParent(relatedParent0);
|
|
}
|
|
|
|
const relatedParent1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Invoice1 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Invoice1?.setParent) {
|
|
await Invoice1.setParent(relatedParent1);
|
|
}
|
|
|
|
const relatedParent2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Invoice2 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Invoice2?.setParent) {
|
|
await Invoice2.setParent(relatedParent2);
|
|
}
|
|
|
|
const relatedParent3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Invoice3 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Invoice3?.setParent) {
|
|
await Invoice3.setParent(relatedParent3);
|
|
}
|
|
}
|
|
|
|
async function associateInvoiceWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Invoice0 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Invoice0?.setSchool) {
|
|
await Invoice0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Invoice1 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Invoice1?.setSchool) {
|
|
await Invoice1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Invoice2 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Invoice2?.setSchool) {
|
|
await Invoice2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Invoice3 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Invoice3?.setSchool) {
|
|
await Invoice3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateSubjectWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject0 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Subject0?.setSchool) {
|
|
await Subject0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject1 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Subject1?.setSchool) {
|
|
await Subject1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject2 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Subject2?.setSchool) {
|
|
await Subject2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject3 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Subject3?.setSchool) {
|
|
await Subject3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Announcements.bulkCreate(AnnouncementsData);
|
|
|
|
await AttendanceRecords.bulkCreate(AttendanceRecordsData);
|
|
|
|
await Classes.bulkCreate(ClassesData);
|
|
|
|
await Grades.bulkCreate(GradesData);
|
|
|
|
await Invoices.bulkCreate(InvoicesData);
|
|
|
|
await Subjects.bulkCreate(SubjectsData);
|
|
|
|
await Schools.bulkCreate(SchoolsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithSchool(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateAnnouncementWithSchool(),
|
|
|
|
await associateAttendanceRecordWithStudent(),
|
|
|
|
await associateAttendanceRecordWithSchool(),
|
|
|
|
await associateClassWithSchool(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateClassWithSchool(),
|
|
|
|
await associateGradeWithStudent(),
|
|
|
|
await associateGradeWithSubject(),
|
|
|
|
await associateGradeWithSchool(),
|
|
|
|
await associateInvoiceWithParent(),
|
|
|
|
await associateInvoiceWithSchool(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateSubjectWithSchool(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('announcements', null, {});
|
|
|
|
await queryInterface.bulkDelete('attendance_records', null, {});
|
|
|
|
await queryInterface.bulkDelete('classes', null, {});
|
|
|
|
await queryInterface.bulkDelete('grades', null, {});
|
|
|
|
await queryInterface.bulkDelete('invoices', null, {});
|
|
|
|
await queryInterface.bulkDelete('subjects', null, {});
|
|
|
|
await queryInterface.bulkDelete('schools', null, {});
|
|
},
|
|
};
|