1859 lines
35 KiB
JavaScript
1859 lines
35 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 CoursesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Product Management Foundations",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"subtitle": "Build roadmaps and ship with confidence",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "A practical introduction to product management: discovery, prioritization, roadmapping, and stakeholder communication.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "published",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "Business",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"level": "Beginner",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"language": "English",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"price": 49.99,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_free": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"published_at": new Date('2026-02-10T10:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Modern JavaScript Essentials",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"subtitle": "Core JS skills for real projects",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Learn modern JavaScript syntax, async patterns, modules, and best practices through hands-on examples.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "draft",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "Software Development",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"level": "Beginner",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"language": "English",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"price": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_free": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"published_at": new Date('2026-01-15T09:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Web APIs with Node.js",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"subtitle": "Design and build reliable backends",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Build REST APIs with Node.js, validation, error handling, authentication concepts, and performance basics.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "published",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "Software Development",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"level": "Intermediate",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"language": "English",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"price": 79.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_free": false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"published_at": new Date('2026-04-01T09:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Effective Study Habits",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"subtitle": "A system for consistent learning",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Create a simple learning system: goals, routines, spaced repetition, and reflective practice.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "published",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "Personal Development",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"level": "Beginner",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"language": "English",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"price": 19.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_free": false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"published_at": new Date('2026-02-01T12:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const LessonsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "What Product Managers Do",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Overview of product responsibilities, collaboration, and outcomes.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"video_url": "https://videos.example.com/pm-foundations/lesson-1",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"order_index": 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"lesson_type": "video",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "published",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"estimated_minutes": 12,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"release_at": new Date('2026-02-10T10:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Customer Discovery Basics",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "How to run interviews, synthesize insights, and avoid bias.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"video_url": "https://videos.example.com/pm-foundations/lesson-2",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"order_index": 2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"lesson_type": "text",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "draft",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"estimated_minutes": 18,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"release_at": new Date('2026-02-11T10:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "ES6 Syntax Refresher",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Let and const, arrow functions, template literals, and destructuring.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"video_url": "https://videos.example.com/js-essentials/lesson-1",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"order_index": 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"lesson_type": "resource",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "draft",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"estimated_minutes": 15,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"release_at": new Date('2026-01-15T09:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Async JavaScript",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Promises, async-await, error handling, and common async patterns.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"video_url": "https://videos.example.com/js-essentials/lesson-2",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"order_index": 2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"lesson_type": "quiz",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "archived",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"estimated_minutes": 22,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"release_at": new Date('2026-01-16T09:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const EnrollmentsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "active",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"enrolled_at": new Date('2026-02-12T16:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completed_at": new Date('2026-03-01T17:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"course_progress_percent": 66.7,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_activity_at": new Date('2026-03-07T20:10:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "active",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"enrolled_at": new Date('2026-01-20T09:15:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completed_at": new Date('2026-02-05T18:30:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"course_progress_percent": 100,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_activity_at": new Date('2026-02-05T18:30:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "dropped",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"enrolled_at": new Date('2026-02-10T08:45:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completed_at": new Date('2026-03-08T10:20:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"course_progress_percent": 75,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_activity_at": new Date('2026-03-09T11:10:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "completed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"enrolled_at": new Date('2026-02-03T13:05:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completed_at": new Date('2026-03-05T15:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"course_progress_percent": 50,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_activity_at": new Date('2026-03-06T07:25:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const LessonProgressData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "in_progress",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 100,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-02-12T16:10:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completed_at": new Date('2026-02-12T16:40:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_viewed_at": new Date('2026-02-12T16:40:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time_spent_seconds": 1800,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "completed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 60,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-02-13T17:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completed_at": new Date('2026-03-01T17:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_viewed_at": new Date('2026-03-07T20:10:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time_spent_seconds": 2400,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "in_progress",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 100,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-01-20T09:20:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completed_at": new Date('2026-01-20T09:50:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_viewed_at": new Date('2026-02-05T18:30:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time_spent_seconds": 1800,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "not_started",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 100,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-01-22T10:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"completed_at": new Date('2026-01-22T10:35:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_viewed_at": new Date('2026-02-05T18:30:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time_spent_seconds": 2100,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Courses.bulkCreate(CoursesData);
|
|
|
|
|
|
|
|
|
|
await Lessons.bulkCreate(LessonsData);
|
|
|
|
|
|
|
|
|
|
await Enrollments.bulkCreate(EnrollmentsData);
|
|
|
|
|
|
|
|
|
|
await LessonProgress.bulkCreate(LessonProgressData);
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateCoursWithInstructor(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateLessonWithCourse(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateEnrollmentWithStudent(),
|
|
|
|
|
|
|
|
|
|
await associateEnrollmentWithCourse(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateLessonProgresWithEnrollment(),
|
|
|
|
|
|
|
|
|
|
await associateLessonProgresWithLesson(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
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, {});
|
|
|
|
|
|
},
|
|
}; |