40093-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-05-26 12:29:23 +00:00

2705 lines
52 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Courses = db.courses;
const Lessons = db.lessons;
const Enrollments = db.enrollments;
const LessonProgress = db.lesson_progress;
const CourseAnnouncements = db.course_announcements;
const CourseReviews = db.course_reviews;
const CoursesData = [
{
"title": "Project Management Fundamentals",
"slug": "project-management-fundamentals",
"short_description": "Learn core project management concepts, planning, and execution techniques.",
"description": "A practical introduction to initiating, planning, executing, and closing projects with confidence.",
// type code here for "images" field
"status": "draft",
"price": 79.0,
"level": "Beginner",
"language": "English",
"published_at": new Date('2026-04-10T10:00:00Z'),
// type code here for "relation_one" field
},
{
"title": "Data Analysis with Spreadsheets",
"slug": "data-analysis-with-spreadsheets",
"short_description": "Build strong spreadsheet skills for analysis, reporting, and dashboards.",
"description": "Learn formulas, pivot tables, data cleaning, and practical reporting workflows.",
// type code here for "images" field
"status": "published",
"price": 59.0,
"level": "Beginner",
"language": "English",
"published_at": new Date('2026-04-18T10:00:00Z'),
// type code here for "relation_one" field
},
{
"title": "Effective Business Writing",
"slug": "effective-business-writing",
"short_description": "Write clear, concise emails, docs, and proposals for workplace success.",
"description": "Improve structure, tone, and clarity with repeatable writing templates and examples.",
// type code here for "images" field
"status": "archived",
"price": 49.0,
"level": "Beginner",
"language": "English",
"published_at": new Date('2026-06-15T10:00:00Z'),
// type code here for "relation_one" field
},
{
"title": "Introduction to UX Research",
"slug": "introduction-to-ux-research",
"short_description": "Learn UX research methods to understand users and make better product decisions.",
"description": "From interviews to usability testing, practice fundamentals and reporting insights.",
// type code here for "images" field
"status": "archived",
"price": 99.0,
"level": "Intermediate",
"language": "English",
"published_at": new Date('2026-03-28T10:00:00Z'),
// type code here for "relation_one" field
},
];
const LessonsData = [
{
// type code here for "relation_one" field
"title": "Course Overview and Outcomes",
"summary": "Understand what you will learn and how to use the course resources.",
"content_type": "text",
"content": "Welcome to the course. In this lesson we outline goals, structure, and expectations.",
"video_url": "https://example.com/videos/pm-01",
// type code here for "files" field
"external_url": "https://example.com/resources/pm-overview",
"position": 1,
"status": "draft",
"is_free_preview": true,
"estimated_minutes": 12.0,
"available_from": new Date('2026-04-10T10:00:00Z'),
"available_until": new Date('2026-12-31T23:59:00Z'),
},
{
// type code here for "relation_one" field
"title": "Building a Simple Project Plan",
"summary": "Create scope, milestones, and a timeline using a lightweight template.",
"content_type": "video",
"content": "Download the template and follow the steps to create a baseline plan.",
"video_url": "https://example.com/videos/pm-02",
// type code here for "files" field
"external_url": "https://example.com/resources/pm-plan-template",
"position": 2,
"status": "draft",
"is_free_preview": false,
"estimated_minutes": 25.0,
"available_from": new Date('2026-04-10T10:00:00Z'),
"available_until": new Date('2026-12-31T23:59:00Z'),
},
{
// type code here for "relation_one" field
"title": "Spreadsheet Essentials and Shortcuts",
"summary": "Navigate spreadsheets efficiently and use essential shortcuts.",
"content_type": "file",
"content": "This lesson covers navigation, formatting, and productivity shortcuts.",
"video_url": "https://example.com/videos/ss-01",
// type code here for "files" field
"external_url": "https://example.com/resources/ss-shortcuts",
"position": 1,
"status": "published",
"is_free_preview": true,
"estimated_minutes": 18.0,
"available_from": new Date('2026-04-18T10:00:00Z'),
"available_until": new Date('2026-12-31T23:59:00Z'),
},
{
// type code here for "relation_one" field
"title": "Pivot Tables for Reporting",
"summary": "Summarize datasets and build reports with pivot tables.",
"content_type": "quiz",
"content": "Learn to create pivot tables, group data, and format reports for stakeholders.",
"video_url": "https://example.com/videos/ss-02",
// type code here for "files" field
"external_url": "https://example.com/resources/pivot-guide",
"position": 2,
"status": "published",
"is_free_preview": false,
"estimated_minutes": 22.0,
"available_from": new Date('2026-04-18T10:00:00Z'),
"available_until": new Date('2026-12-31T23:59:00Z'),
},
];
const EnrollmentsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "active",
"enrolled_at": new Date('2026-04-15T13:20:00Z'),
"completed_at": new Date('2026-06-30T17:00:00Z'),
"progress_percent": 40.0,
"last_position": 2.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"enrolled_at": new Date('2026-04-20T09:10:00Z'),
"completed_at": new Date('2026-07-15T17:00:00Z'),
"progress_percent": 55.0,
"last_position": 2.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"enrolled_at": new Date('2026-04-12T16:00:00Z'),
"completed_at": new Date('2026-05-10T15:30:00Z'),
"progress_percent": 100.0,
"last_position": 2.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "cancelled",
"enrolled_at": new Date('2026-04-02T10:25:00Z'),
"completed_at": new Date('2026-08-01T17:00:00Z'),
"progress_percent": 25.0,
"last_position": 1.0,
},
];
const LessonProgressData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "in_progress",
"is_completed": true,
"started_at": new Date('2026-04-15T13:30:00Z'),
"completed_at": new Date('2026-04-15T13:50:00Z'),
"time_spent_seconds": 1200,
"score": 100.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "not_started",
"is_completed": true,
"started_at": new Date('2026-04-16T10:00:00Z'),
"completed_at": new Date('2026-04-16T10:20:00Z'),
"time_spent_seconds": 900,
"score": 0.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "not_started",
"is_completed": true,
"started_at": new Date('2026-04-20T09:20:00Z'),
"completed_at": new Date('2026-04-20T09:45:00Z'),
"time_spent_seconds": 1500,
"score": 95.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"is_completed": false,
"started_at": new Date('2026-04-21T11:10:00Z'),
"completed_at": new Date('2026-04-21T11:25:00Z'),
"time_spent_seconds": 900,
"score": 0.0,
},
];
const CourseAnnouncementsData = [
{
// type code here for "relation_one" field
"title": "Welcome and Getting Started",
"message": "Welcome to the course. Please review the overview lesson and download the project plan template.",
"visibility": "public",
"scheduled_at": new Date('2026-04-10T09:30:00Z'),
"published_at": new Date('2026-04-10T10:05:00Z'),
"is_pinned": true,
},
{
// type code here for "relation_one" field
"title": "Dataset for Pivot Table Lesson",
"message": "A practice dataset is available in the resources link for the pivot table lesson.",
"visibility": "public",
"scheduled_at": new Date('2026-04-18T09:30:00Z'),
"published_at": new Date('2026-04-18T10:10:00Z'),
"is_pinned": true,
},
{
// type code here for "relation_one" field
"title": "Live Q and A Session",
"message": "We will host a live Q and A session to discuss interview planning and analysis.",
"visibility": "enrolled_only",
"scheduled_at": new Date('2026-04-07T16:00:00Z'),
"published_at": new Date('2026-04-07T16:05:00Z'),
"is_pinned": false,
},
{
// type code here for "relation_one" field
"title": "Office Hours This Week",
"message": "Office hours are open this Thursday. Bring your project plan questions.",
"visibility": "enrolled_only",
"scheduled_at": new Date('2026-04-21T15:00:00Z'),
"published_at": new Date('2026-04-21T15:05:00Z'),
"is_pinned": true,
},
];
const CourseReviewsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 5,
"headline": "Clear and practical",
"review_text": "The templates and examples made it easy to apply immediately at work.",
"status": "published",
"submitted_at": new Date('2026-05-11T09:00:00Z'),
"moderated_at": new Date('2026-05-11T12:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 4,
"headline": "Very helpful for reporting",
"review_text": "Strong coverage of pivots and basic cleaning. Would love more charting examples.",
"status": "published",
"submitted_at": new Date('2026-05-05T10:30:00Z'),
"moderated_at": new Date('2026-05-05T13:15:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 5,
"headline": "Great UX research primer",
"review_text": "The interview checklist and structure for notes were especially useful.",
"status": "hidden",
"submitted_at": new Date('2026-04-20T08:10:00Z'),
"moderated_at": new Date('2026-04-20T10:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 4,
"headline": "Good overview",
"review_text": "Solid fundamentals and a clear approach to planning and milestones.",
"status": "pending",
"submitted_at": new Date('2026-04-28T17:40:00Z'),
"moderated_at": new Date('2026-05-01T09:00:00Z'),
},
];
// Similar logic for "relation_many"
async function associateCoursWithInstructor() {
const relatedInstructor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Cours0 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Cours0?.setInstructor)
{
await
Cours0.
setInstructor(relatedInstructor0);
}
const relatedInstructor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Cours1 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Cours1?.setInstructor)
{
await
Cours1.
setInstructor(relatedInstructor1);
}
const relatedInstructor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Cours2 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Cours2?.setInstructor)
{
await
Cours2.
setInstructor(relatedInstructor2);
}
const relatedInstructor3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Cours3 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Cours3?.setInstructor)
{
await
Cours3.
setInstructor(relatedInstructor3);
}
}
async function associateLessonWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson0 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Lesson0?.setCourse)
{
await
Lesson0.
setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson1 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Lesson1?.setCourse)
{
await
Lesson1.
setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson2 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Lesson2?.setCourse)
{
await
Lesson2.
setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson3 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Lesson3?.setCourse)
{
await
Lesson3.
setCourse(relatedCourse3);
}
}
async function associateEnrollmentWithStudent() {
const relatedStudent0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Enrollment0 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Enrollment0?.setStudent)
{
await
Enrollment0.
setStudent(relatedStudent0);
}
const relatedStudent1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Enrollment1 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Enrollment1?.setStudent)
{
await
Enrollment1.
setStudent(relatedStudent1);
}
const relatedStudent2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Enrollment2 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Enrollment2?.setStudent)
{
await
Enrollment2.
setStudent(relatedStudent2);
}
const relatedStudent3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Enrollment3 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Enrollment3?.setStudent)
{
await
Enrollment3.
setStudent(relatedStudent3);
}
}
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);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Enrollment3 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Enrollment3?.setCourse)
{
await
Enrollment3.
setCourse(relatedCourse3);
}
}
async function associateLessonProgresWithEnrollment() {
const relatedEnrollment0 = await Enrollments.findOne({
offset: Math.floor(Math.random() * (await Enrollments.count())),
});
const LessonProgres0 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (LessonProgres0?.setEnrollment)
{
await
LessonProgres0.
setEnrollment(relatedEnrollment0);
}
const relatedEnrollment1 = await Enrollments.findOne({
offset: Math.floor(Math.random() * (await Enrollments.count())),
});
const LessonProgres1 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (LessonProgres1?.setEnrollment)
{
await
LessonProgres1.
setEnrollment(relatedEnrollment1);
}
const relatedEnrollment2 = await Enrollments.findOne({
offset: Math.floor(Math.random() * (await Enrollments.count())),
});
const LessonProgres2 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (LessonProgres2?.setEnrollment)
{
await
LessonProgres2.
setEnrollment(relatedEnrollment2);
}
const relatedEnrollment3 = await Enrollments.findOne({
offset: Math.floor(Math.random() * (await Enrollments.count())),
});
const LessonProgres3 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (LessonProgres3?.setEnrollment)
{
await
LessonProgres3.
setEnrollment(relatedEnrollment3);
}
}
async function associateLessonProgresWithLesson() {
const relatedLesson0 = await Lessons.findOne({
offset: Math.floor(Math.random() * (await Lessons.count())),
});
const LessonProgres0 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (LessonProgres0?.setLesson)
{
await
LessonProgres0.
setLesson(relatedLesson0);
}
const relatedLesson1 = await Lessons.findOne({
offset: Math.floor(Math.random() * (await Lessons.count())),
});
const LessonProgres1 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (LessonProgres1?.setLesson)
{
await
LessonProgres1.
setLesson(relatedLesson1);
}
const relatedLesson2 = await Lessons.findOne({
offset: Math.floor(Math.random() * (await Lessons.count())),
});
const LessonProgres2 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (LessonProgres2?.setLesson)
{
await
LessonProgres2.
setLesson(relatedLesson2);
}
const relatedLesson3 = await Lessons.findOne({
offset: Math.floor(Math.random() * (await Lessons.count())),
});
const LessonProgres3 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (LessonProgres3?.setLesson)
{
await
LessonProgres3.
setLesson(relatedLesson3);
}
}
async function associateCourseAnnouncementWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseAnnouncement0 = await CourseAnnouncements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (CourseAnnouncement0?.setCourse)
{
await
CourseAnnouncement0.
setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseAnnouncement1 = await CourseAnnouncements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (CourseAnnouncement1?.setCourse)
{
await
CourseAnnouncement1.
setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseAnnouncement2 = await CourseAnnouncements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (CourseAnnouncement2?.setCourse)
{
await
CourseAnnouncement2.
setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseAnnouncement3 = await CourseAnnouncements.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (CourseAnnouncement3?.setCourse)
{
await
CourseAnnouncement3.
setCourse(relatedCourse3);
}
}
async function associateCourseReviewWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseReview0 = await CourseReviews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (CourseReview0?.setCourse)
{
await
CourseReview0.
setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseReview1 = await CourseReviews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (CourseReview1?.setCourse)
{
await
CourseReview1.
setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseReview2 = await CourseReviews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (CourseReview2?.setCourse)
{
await
CourseReview2.
setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseReview3 = await CourseReviews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (CourseReview3?.setCourse)
{
await
CourseReview3.
setCourse(relatedCourse3);
}
}
async function associateCourseReviewWithStudent() {
const relatedStudent0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CourseReview0 = await CourseReviews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (CourseReview0?.setStudent)
{
await
CourseReview0.
setStudent(relatedStudent0);
}
const relatedStudent1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CourseReview1 = await CourseReviews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (CourseReview1?.setStudent)
{
await
CourseReview1.
setStudent(relatedStudent1);
}
const relatedStudent2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CourseReview2 = await CourseReviews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (CourseReview2?.setStudent)
{
await
CourseReview2.
setStudent(relatedStudent2);
}
const relatedStudent3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CourseReview3 = await CourseReviews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (CourseReview3?.setStudent)
{
await
CourseReview3.
setStudent(relatedStudent3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Courses.bulkCreate(CoursesData);
await Lessons.bulkCreate(LessonsData);
await Enrollments.bulkCreate(EnrollmentsData);
await LessonProgress.bulkCreate(LessonProgressData);
await CourseAnnouncements.bulkCreate(CourseAnnouncementsData);
await CourseReviews.bulkCreate(CourseReviewsData);
await Promise.all([
// Similar logic for "relation_many"
await associateCoursWithInstructor(),
await associateLessonWithCourse(),
await associateEnrollmentWithStudent(),
await associateEnrollmentWithCourse(),
await associateLessonProgresWithEnrollment(),
await associateLessonProgresWithLesson(),
await associateCourseAnnouncementWithCourse(),
await associateCourseReviewWithCourse(),
await associateCourseReviewWithStudent(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('courses', null, {});
await queryInterface.bulkDelete('lessons', null, {});
await queryInterface.bulkDelete('enrollments', null, {});
await queryInterface.bulkDelete('lesson_progress', null, {});
await queryInterface.bulkDelete('course_announcements', null, {});
await queryInterface.bulkDelete('course_reviews', null, {});
},
};