226/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-16 18:39:13 +00:00

379 lines
8.2 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Analytics = db.analytics;
const Courses = db.courses;
const DiscussionBoards = db.discussion_boards;
const Enrollments = db.enrollments;
const Instructors = db.instructors;
const Students = db.students;
const AnalyticsData = [
{
// type code here for "relation_one" field
engagement_rate: 75.5,
completion_rate: 60,
instructor_performance: 85,
},
{
// type code here for "relation_one" field
engagement_rate: 80,
completion_rate: 70,
instructor_performance: 90,
},
{
// type code here for "relation_one" field
engagement_rate: 65,
completion_rate: 50,
instructor_performance: 78,
},
];
const CoursesData = [
{
title: 'Introduction to Programming',
syllabus: 'Learn the basics of programming using Python.',
// type code here for "files" field
// type code here for "relation_many" field
},
{
title: 'Advanced Mathematics',
syllabus: 'Explore advanced topics in calculus and algebra.',
// type code here for "files" field
// type code here for "relation_many" field
},
{
title: 'Modern Art History',
syllabus: 'Study the evolution of modern art from the 19th century.',
// type code here for "files" field
// type code here for "relation_many" field
},
];
const DiscussionBoardsData = [
{
topic: 'Introduction to Programming - Week 1',
// type code here for "relation_one" field
},
{
topic: 'Advanced Mathematics - Calculus',
// type code here for "relation_one" field
},
{
topic: 'Modern Art History - Impressionism',
// type code here for "relation_one" field
},
];
const EnrollmentsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'Pending',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'Completed',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'Pending',
},
];
const InstructorsData = [
{
name: 'Dr. Sarah Lee',
qualifications: 'PhD in Computer Science',
// type code here for "relation_many" field
},
{
name: 'Prof. Mark Taylor',
qualifications: 'MBA in Business Administration',
// type code here for "relation_many" field
},
{
name: 'Dr. Laura White',
qualifications: 'PhD in Art History',
// type code here for "relation_many" field
},
];
const StudentsData = [
{
first_name: 'Alice',
last_name: 'Williams',
email: 'alice.williams@example.com',
// type code here for "relation_many" field
},
{
first_name: 'David',
last_name: 'Miller',
email: 'david.miller@example.com',
// type code here for "relation_many" field
},
{
first_name: 'Sophia',
last_name: 'Davis',
email: 'sophia.davis@example.com',
// type code here for "relation_many" field
},
];
// Similar logic for "relation_many"
async function associateAnalyticWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Analytic0 = await Analytics.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Analytic0?.setCourse) {
await Analytic0.setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Analytic1 = await Analytics.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Analytic1?.setCourse) {
await Analytic1.setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Analytic2 = await Analytics.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Analytic2?.setCourse) {
await Analytic2.setCourse(relatedCourse2);
}
}
// Similar logic for "relation_many"
async function associateDiscussionBoardWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const DiscussionBoard0 = await DiscussionBoards.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (DiscussionBoard0?.setCourse) {
await DiscussionBoard0.setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const DiscussionBoard1 = await DiscussionBoards.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (DiscussionBoard1?.setCourse) {
await DiscussionBoard1.setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const DiscussionBoard2 = await DiscussionBoards.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (DiscussionBoard2?.setCourse) {
await DiscussionBoard2.setCourse(relatedCourse2);
}
}
async function associateEnrollmentWithStudent() {
const relatedStudent0 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Enrollment0 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Enrollment0?.setStudent) {
await Enrollment0.setStudent(relatedStudent0);
}
const relatedStudent1 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Enrollment1 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Enrollment1?.setStudent) {
await Enrollment1.setStudent(relatedStudent1);
}
const relatedStudent2 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Enrollment2 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Enrollment2?.setStudent) {
await Enrollment2.setStudent(relatedStudent2);
}
}
async function associateEnrollmentWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Enrollment0 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Enrollment0?.setCourse) {
await Enrollment0.setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Enrollment1 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Enrollment1?.setCourse) {
await Enrollment1.setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Enrollment2 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Enrollment2?.setCourse) {
await Enrollment2.setCourse(relatedCourse2);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
module.exports = {
up: async (queryInterface, Sequelize) => {
await Analytics.bulkCreate(AnalyticsData);
await Courses.bulkCreate(CoursesData);
await DiscussionBoards.bulkCreate(DiscussionBoardsData);
await Enrollments.bulkCreate(EnrollmentsData);
await Instructors.bulkCreate(InstructorsData);
await Students.bulkCreate(StudentsData);
await Promise.all([
// Similar logic for "relation_many"
await associateAnalyticWithCourse(),
// Similar logic for "relation_many"
await associateDiscussionBoardWithCourse(),
await associateEnrollmentWithStudent(),
await associateEnrollmentWithCourse(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('analytics', null, {});
await queryInterface.bulkDelete('courses', null, {});
await queryInterface.bulkDelete('discussion_boards', null, {});
await queryInterface.bulkDelete('enrollments', null, {});
await queryInterface.bulkDelete('instructors', null, {});
await queryInterface.bulkDelete('students', null, {});
},
};