32194/backend/src/db/seeders/20231127130745-sample-data.js
2025-06-12 23:31:04 +00:00

708 lines
16 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Courses = db.courses;
const Credentials = db.credentials;
const Feedback = db.feedback;
const Lessons = db.lessons;
const Progress = db.progress;
const CoursesData = [
{
title: 'Introduction to AI',
description: 'Learn the basics of artificial intelligence.',
published_at: new Date('2023-10-01T10:00:00Z'),
},
{
title: 'Web Development 101',
description: "A beginner's guide to web development.",
published_at: new Date('2023-10-02T11:00:00Z'),
},
{
title: 'Data Science Essentials',
description: 'Understand the fundamentals of data science.',
published_at: new Date('2023-10-03T12:00:00Z'),
},
{
title: 'Digital Marketing Basics',
description: 'Explore the world of digital marketing.',
published_at: new Date('2023-10-04T13:00:00Z'),
},
{
title: 'Project Management Skills',
description: 'Develop essential project management skills.',
published_at: new Date('2023-10-05T14:00:00Z'),
},
];
const CredentialsData = [
{
credential_id: 'CRD-001',
// type code here for "relation_one" field
// type code here for "relation_one" field
issued_at: new Date('2023-10-06T15:00:00Z'),
},
{
credential_id: 'CRD-002',
// type code here for "relation_one" field
// type code here for "relation_one" field
issued_at: new Date('2023-10-07T16:00:00Z'),
},
{
credential_id: 'CRD-003',
// type code here for "relation_one" field
// type code here for "relation_one" field
issued_at: new Date('2023-10-08T17:00:00Z'),
},
{
credential_id: 'CRD-004',
// type code here for "relation_one" field
// type code here for "relation_one" field
issued_at: new Date('2023-10-09T18:00:00Z'),
},
{
credential_id: 'CRD-005',
// type code here for "relation_one" field
// type code here for "relation_one" field
issued_at: new Date('2023-10-10T19:00:00Z'),
},
];
const FeedbackData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
rating: 5,
comments: 'Great course, very informative!',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
rating: 4,
comments: 'Good introduction to web development.',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
rating: 5,
comments: 'Excellent content and well explained.',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
rating: 3,
comments: 'Informative but could use more examples.',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
rating: 4,
comments: 'Useful insights into project management.',
},
];
const LessonsData = [
{
title: 'AI Concepts',
content: 'Introduction to AI concepts and applications.',
// type code here for "relation_one" field
duration_minutes: 10,
},
{
title: 'HTML Basics',
content: 'Learn the basics of HTML for web development.',
// type code here for "relation_one" field
duration_minutes: 15,
},
{
title: 'Data Analysis Techniques',
content: 'Explore various data analysis techniques.',
// type code here for "relation_one" field
duration_minutes: 12,
},
{
title: 'SEO Strategies',
content: 'Understand SEO strategies for digital marketing.',
// type code here for "relation_one" field
duration_minutes: 8,
},
{
title: 'Agile Methodology',
content: 'Learn about Agile methodology in project management.',
// type code here for "relation_one" field
duration_minutes: 14,
},
];
const ProgressData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
completed_lessons: 5,
total_lessons: 10,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
completed_lessons: 3,
total_lessons: 8,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
completed_lessons: 7,
total_lessons: 12,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
completed_lessons: 4,
total_lessons: 6,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
completed_lessons: 6,
total_lessons: 10,
},
];
// Similar logic for "relation_many"
async function associateCredentialWithLearner() {
const relatedLearner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Credential0 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Credential0?.setLearner) {
await Credential0.setLearner(relatedLearner0);
}
const relatedLearner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Credential1 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Credential1?.setLearner) {
await Credential1.setLearner(relatedLearner1);
}
const relatedLearner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Credential2 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Credential2?.setLearner) {
await Credential2.setLearner(relatedLearner2);
}
const relatedLearner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Credential3 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Credential3?.setLearner) {
await Credential3.setLearner(relatedLearner3);
}
const relatedLearner4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Credential4 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Credential4?.setLearner) {
await Credential4.setLearner(relatedLearner4);
}
}
async function associateCredentialWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Credential0 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Credential0?.setCourse) {
await Credential0.setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Credential1 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Credential1?.setCourse) {
await Credential1.setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Credential2 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Credential2?.setCourse) {
await Credential2.setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Credential3 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Credential3?.setCourse) {
await Credential3.setCourse(relatedCourse3);
}
const relatedCourse4 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Credential4 = await Credentials.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Credential4?.setCourse) {
await Credential4.setCourse(relatedCourse4);
}
}
async function associateFeedbackWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Feedback0 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Feedback0?.setCourse) {
await Feedback0.setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Feedback1 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Feedback1?.setCourse) {
await Feedback1.setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Feedback2 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Feedback2?.setCourse) {
await Feedback2.setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Feedback3 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Feedback3?.setCourse) {
await Feedback3.setCourse(relatedCourse3);
}
const relatedCourse4 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Feedback4 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Feedback4?.setCourse) {
await Feedback4.setCourse(relatedCourse4);
}
}
async function associateFeedbackWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Feedback0 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Feedback0?.setUser) {
await Feedback0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Feedback1 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Feedback1?.setUser) {
await Feedback1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Feedback2 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Feedback2?.setUser) {
await Feedback2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Feedback3 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Feedback3?.setUser) {
await Feedback3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Feedback4 = await Feedback.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Feedback4?.setUser) {
await Feedback4.setUser(relatedUser4);
}
}
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);
}
const relatedCourse4 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson4 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Lesson4?.setCourse) {
await Lesson4.setCourse(relatedCourse4);
}
}
async function associateProgressWithLearner() {
const relatedLearner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Progress0 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Progress0?.setLearner) {
await Progress0.setLearner(relatedLearner0);
}
const relatedLearner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Progress1 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Progress1?.setLearner) {
await Progress1.setLearner(relatedLearner1);
}
const relatedLearner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Progress2 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Progress2?.setLearner) {
await Progress2.setLearner(relatedLearner2);
}
const relatedLearner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Progress3 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Progress3?.setLearner) {
await Progress3.setLearner(relatedLearner3);
}
const relatedLearner4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Progress4 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Progress4?.setLearner) {
await Progress4.setLearner(relatedLearner4);
}
}
async function associateProgressWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Progress0 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Progress0?.setCourse) {
await Progress0.setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Progress1 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Progress1?.setCourse) {
await Progress1.setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Progress2 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Progress2?.setCourse) {
await Progress2.setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Progress3 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Progress3?.setCourse) {
await Progress3.setCourse(relatedCourse3);
}
const relatedCourse4 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Progress4 = await Progress.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Progress4?.setCourse) {
await Progress4.setCourse(relatedCourse4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Courses.bulkCreate(CoursesData);
await Credentials.bulkCreate(CredentialsData);
await Feedback.bulkCreate(FeedbackData);
await Lessons.bulkCreate(LessonsData);
await Progress.bulkCreate(ProgressData);
await Promise.all([
// Similar logic for "relation_many"
await associateCredentialWithLearner(),
await associateCredentialWithCourse(),
await associateFeedbackWithCourse(),
await associateFeedbackWithUser(),
await associateLessonWithCourse(),
await associateProgressWithLearner(),
await associateProgressWithCourse(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('courses', null, {});
await queryInterface.bulkDelete('credentials', null, {});
await queryInterface.bulkDelete('feedback', null, {});
await queryInterface.bulkDelete('lessons', null, {});
await queryInterface.bulkDelete('progress', null, {});
},
};