1384 lines
34 KiB
JavaScript
1384 lines
34 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Assignments = db.assignments;
|
|
|
|
const Attendances = db.attendances;
|
|
|
|
const Classes = db.classes;
|
|
|
|
const Messages = db.messages;
|
|
|
|
const Resources = db.resources;
|
|
|
|
const Results = db.results;
|
|
|
|
const Students = db.students;
|
|
|
|
const Subjects = db.subjects;
|
|
|
|
const Teachers = db.teachers;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const AssignmentsData = [
|
|
{
|
|
title: 'That goddamn Datamate',
|
|
|
|
due_date: new Date('2024-08-08'),
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: "It's around here somewhere",
|
|
|
|
due_date: new Date('2024-09-29'),
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Like a red-headed stepchild',
|
|
|
|
due_date: new Date('2024-10-23'),
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'I want my 5$ back',
|
|
|
|
due_date: new Date('2025-03-20'),
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const AttendancesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2025-02-15'),
|
|
|
|
present: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2024-05-12'),
|
|
|
|
present: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2025-02-17'),
|
|
|
|
present: false,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2024-09-07'),
|
|
|
|
present: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ClassesData = [
|
|
{
|
|
name: 'Justus Liebig',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'John Bardeen',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Murray Gell-Mann',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Albert Einstein',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MessagesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Truly wonderful, the mind of a child is.',
|
|
|
|
sent_at: new Date('2024-11-02'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content:
|
|
'Like fire across the galaxy the Clone Wars spread. In league with the wicked Count Dooku, more and more planets slip. Against this threat, upon the Jedi Knights falls the duty to lead the newly formed army of the Republic. And as the heat of war grows, so, to, grows the prowess of one most gifted student of the Force.',
|
|
|
|
sent_at: new Date('2024-10-11'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Your weapons, you will not need them.',
|
|
|
|
sent_at: new Date('2025-04-13'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Luminous beings are we - not this crude matter.',
|
|
|
|
sent_at: new Date('2025-02-03'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ResourcesData = [
|
|
{
|
|
title: 'I want my 5$ back',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'That damn gimble',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Turd gone wrong',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Turd gone wrong',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ResultsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
score: 38.02,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
score: 33.37,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
score: 47.35,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
score: 80.93,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const StudentsData = [
|
|
{
|
|
first_name: 'My boss gonna fire me',
|
|
|
|
last_name: "C'mon Naomi",
|
|
|
|
// 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
|
|
},
|
|
|
|
{
|
|
first_name: 'Always the last one to the party',
|
|
|
|
last_name: 'Texas!',
|
|
|
|
// 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
|
|
},
|
|
|
|
{
|
|
first_name: 'My buddy Harlen',
|
|
|
|
last_name: 'Texas!',
|
|
|
|
// 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
|
|
},
|
|
|
|
{
|
|
first_name: 'That damn Bill Stull',
|
|
|
|
last_name: 'That damn gimble',
|
|
|
|
// 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 SubjectsData = [
|
|
{
|
|
name: 'Alexander Fleming',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Stephen Hawking',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Albrecht von Haller',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Richard Feynman',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TeachersData = [
|
|
{
|
|
first_name: 'Reminds me of my old girlfriend Olga Goodntight',
|
|
|
|
last_name: "That's messed up",
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Texas!',
|
|
|
|
last_name: 'Come on now',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Come on now',
|
|
|
|
last_name: 'Contact the tower',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: "That Barbala couldn't fly his way out of a wet paper bag",
|
|
|
|
last_name: "It's around here somewhere",
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Jean Piaget',
|
|
},
|
|
|
|
{
|
|
name: 'Wilhelm Wundt',
|
|
},
|
|
|
|
{
|
|
name: 'Gustav Kirchhoff',
|
|
},
|
|
|
|
{
|
|
name: 'Marie Curie',
|
|
},
|
|
];
|
|
|
|
// 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 associateAssignmentWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Assignment0 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Assignment0?.setOrganization) {
|
|
await Assignment0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Assignment1 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Assignment1?.setOrganization) {
|
|
await Assignment1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Assignment2 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Assignment2?.setOrganization) {
|
|
await Assignment2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Assignment3 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Assignment3?.setOrganization) {
|
|
await Assignment3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateAttendanceWithStudent() {
|
|
const relatedStudent0 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Attendance0 = await Attendances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Attendance0?.setStudent) {
|
|
await Attendance0.setStudent(relatedStudent0);
|
|
}
|
|
|
|
const relatedStudent1 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Attendance1 = await Attendances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Attendance1?.setStudent) {
|
|
await Attendance1.setStudent(relatedStudent1);
|
|
}
|
|
|
|
const relatedStudent2 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Attendance2 = await Attendances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Attendance2?.setStudent) {
|
|
await Attendance2.setStudent(relatedStudent2);
|
|
}
|
|
|
|
const relatedStudent3 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Attendance3 = await Attendances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Attendance3?.setStudent) {
|
|
await Attendance3.setStudent(relatedStudent3);
|
|
}
|
|
}
|
|
|
|
async function associateAttendanceWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Attendance0 = await Attendances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Attendance0?.setOrganization) {
|
|
await Attendance0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Attendance1 = await Attendances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Attendance1?.setOrganization) {
|
|
await Attendance1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Attendance2 = await Attendances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Attendance2?.setOrganization) {
|
|
await Attendance2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Attendance3 = await Attendances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Attendance3?.setOrganization) {
|
|
await Attendance3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateClassWithTeacher() {
|
|
const relatedTeacher0 = await Teachers.findOne({
|
|
offset: Math.floor(Math.random() * (await Teachers.count())),
|
|
});
|
|
const Class0 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Class0?.setTeacher) {
|
|
await Class0.setTeacher(relatedTeacher0);
|
|
}
|
|
|
|
const relatedTeacher1 = await Teachers.findOne({
|
|
offset: Math.floor(Math.random() * (await Teachers.count())),
|
|
});
|
|
const Class1 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Class1?.setTeacher) {
|
|
await Class1.setTeacher(relatedTeacher1);
|
|
}
|
|
|
|
const relatedTeacher2 = await Teachers.findOne({
|
|
offset: Math.floor(Math.random() * (await Teachers.count())),
|
|
});
|
|
const Class2 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Class2?.setTeacher) {
|
|
await Class2.setTeacher(relatedTeacher2);
|
|
}
|
|
|
|
const relatedTeacher3 = await Teachers.findOne({
|
|
offset: Math.floor(Math.random() * (await Teachers.count())),
|
|
});
|
|
const Class3 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Class3?.setTeacher) {
|
|
await Class3.setTeacher(relatedTeacher3);
|
|
}
|
|
}
|
|
|
|
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 associateMessageWithSender() {
|
|
const relatedSender0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setSender) {
|
|
await Message0.setSender(relatedSender0);
|
|
}
|
|
|
|
const relatedSender1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setSender) {
|
|
await Message1.setSender(relatedSender1);
|
|
}
|
|
|
|
const relatedSender2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setSender) {
|
|
await Message2.setSender(relatedSender2);
|
|
}
|
|
|
|
const relatedSender3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Message3?.setSender) {
|
|
await Message3.setSender(relatedSender3);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithReceiver() {
|
|
const relatedReceiver0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setReceiver) {
|
|
await Message0.setReceiver(relatedReceiver0);
|
|
}
|
|
|
|
const relatedReceiver1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setReceiver) {
|
|
await Message1.setReceiver(relatedReceiver1);
|
|
}
|
|
|
|
const relatedReceiver2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setReceiver) {
|
|
await Message2.setReceiver(relatedReceiver2);
|
|
}
|
|
|
|
const relatedReceiver3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Message3?.setReceiver) {
|
|
await Message3.setReceiver(relatedReceiver3);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setOrganization) {
|
|
await Message0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setOrganization) {
|
|
await Message1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setOrganization) {
|
|
await Message2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Message3?.setOrganization) {
|
|
await Message3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateResourceWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Resource0 = await Resources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Resource0?.setOrganization) {
|
|
await Resource0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Resource1 = await Resources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Resource1?.setOrganization) {
|
|
await Resource1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Resource2 = await Resources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Resource2?.setOrganization) {
|
|
await Resource2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Resource3 = await Resources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Resource3?.setOrganization) {
|
|
await Resource3.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 associateResultWithSubject() {
|
|
const relatedSubject0 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Result0 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Result0?.setSubject) {
|
|
await Result0.setSubject(relatedSubject0);
|
|
}
|
|
|
|
const relatedSubject1 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Result1 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Result1?.setSubject) {
|
|
await Result1.setSubject(relatedSubject1);
|
|
}
|
|
|
|
const relatedSubject2 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Result2 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Result2?.setSubject) {
|
|
await Result2.setSubject(relatedSubject2);
|
|
}
|
|
|
|
const relatedSubject3 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Result3 = await Results.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Result3?.setSubject) {
|
|
await Result3.setSubject(relatedSubject3);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
async function associateStudentWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Student0 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Student0?.setUser) {
|
|
await Student0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Student1 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Student1?.setUser) {
|
|
await Student1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Student2 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Student2?.setUser) {
|
|
await Student2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Student3 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Student3?.setUser) {
|
|
await Student3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
// 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"
|
|
|
|
async function associateSubjectWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Subject0 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Subject0?.setOrganization) {
|
|
await Subject0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Subject1 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Subject1?.setOrganization) {
|
|
await Subject1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Subject2 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Subject2?.setOrganization) {
|
|
await Subject2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Subject3 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Subject3?.setOrganization) {
|
|
await Subject3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateTeacherWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Teacher0 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Teacher0?.setUser) {
|
|
await Teacher0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Teacher1 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Teacher1?.setUser) {
|
|
await Teacher1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Teacher2 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Teacher2?.setUser) {
|
|
await Teacher2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Teacher3 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Teacher3?.setUser) {
|
|
await Teacher3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Assignments.bulkCreate(AssignmentsData);
|
|
|
|
await Attendances.bulkCreate(AttendancesData);
|
|
|
|
await Classes.bulkCreate(ClassesData);
|
|
|
|
await Messages.bulkCreate(MessagesData);
|
|
|
|
await Resources.bulkCreate(ResourcesData);
|
|
|
|
await Results.bulkCreate(ResultsData);
|
|
|
|
await Students.bulkCreate(StudentsData);
|
|
|
|
await Subjects.bulkCreate(SubjectsData);
|
|
|
|
await Teachers.bulkCreate(TeachersData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateAssignmentWithOrganization(),
|
|
|
|
await associateAttendanceWithStudent(),
|
|
|
|
await associateAttendanceWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateClassWithTeacher(),
|
|
|
|
await associateClassWithOrganization(),
|
|
|
|
await associateMessageWithSender(),
|
|
|
|
await associateMessageWithReceiver(),
|
|
|
|
await associateMessageWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateResourceWithOrganization(),
|
|
|
|
await associateResultWithStudent(),
|
|
|
|
await associateResultWithSubject(),
|
|
|
|
await associateResultWithOrganization(),
|
|
|
|
await associateStudentWithUser(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateStudentWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateSubjectWithOrganization(),
|
|
|
|
await associateTeacherWithUser(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateTeacherWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('assignments', null, {});
|
|
|
|
await queryInterface.bulkDelete('attendances', null, {});
|
|
|
|
await queryInterface.bulkDelete('classes', null, {});
|
|
|
|
await queryInterface.bulkDelete('messages', null, {});
|
|
|
|
await queryInterface.bulkDelete('resources', null, {});
|
|
|
|
await queryInterface.bulkDelete('results', null, {});
|
|
|
|
await queryInterface.bulkDelete('students', null, {});
|
|
|
|
await queryInterface.bulkDelete('subjects', null, {});
|
|
|
|
await queryInterface.bulkDelete('teachers', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|