31069/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-28 19:52:54 +00:00

351 lines
8.3 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Connections = db.connections;
const ProgressTracks = db.progress_tracks;
const Skills = db.skills;
const ConnectionsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'accepted',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'pending',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'pending',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'pending',
},
];
const ProgressTracksData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
progress_percentage: 50,
start_date: new Date('2023-01-01T00:00:00Z'),
end_date: new Date('2023-06-01T00:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
progress_percentage: 75,
start_date: new Date('2023-02-01T00:00:00Z'),
end_date: new Date('2023-07-01T00:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
progress_percentage: 30,
start_date: new Date('2023-03-01T00:00:00Z'),
end_date: new Date('2023-08-01T00:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
progress_percentage: 60,
start_date: new Date('2023-04-01T00:00:00Z'),
end_date: new Date('2023-09-01T00:00:00Z'),
},
];
const SkillsData = [
{
name: 'Python Programming',
description:
'Learn the basics of Python programming, including syntax, data structures, and algorithms.',
// type code here for "relation_many" field
},
{
name: 'Digital Marketing',
description:
'Understand the fundamentals of digital marketing, including SEO, social media, and content marketing.',
// type code here for "relation_many" field
},
{
name: 'Graphic Design',
description:
'Explore the principles of graphic design, including typography, color theory, and layout.',
// type code here for "relation_many" field
},
{
name: 'Project Management',
description:
'Gain skills in project management methodologies, tools, and best practices.',
// type code here for "relation_many" field
},
];
// Similar logic for "relation_many"
async function associateConnectionWithLearner() {
const relatedLearner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Connection0 = await Connections.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Connection0?.setLearner) {
await Connection0.setLearner(relatedLearner0);
}
const relatedLearner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Connection1 = await Connections.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Connection1?.setLearner) {
await Connection1.setLearner(relatedLearner1);
}
const relatedLearner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Connection2 = await Connections.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Connection2?.setLearner) {
await Connection2.setLearner(relatedLearner2);
}
const relatedLearner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Connection3 = await Connections.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Connection3?.setLearner) {
await Connection3.setLearner(relatedLearner3);
}
}
async function associateConnectionWithMentor() {
const relatedMentor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Connection0 = await Connections.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Connection0?.setMentor) {
await Connection0.setMentor(relatedMentor0);
}
const relatedMentor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Connection1 = await Connections.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Connection1?.setMentor) {
await Connection1.setMentor(relatedMentor1);
}
const relatedMentor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Connection2 = await Connections.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Connection2?.setMentor) {
await Connection2.setMentor(relatedMentor2);
}
const relatedMentor3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Connection3 = await Connections.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Connection3?.setMentor) {
await Connection3.setMentor(relatedMentor3);
}
}
async function associateProgressTrackWithLearner() {
const relatedLearner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ProgressTrack0 = await ProgressTracks.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (ProgressTrack0?.setLearner) {
await ProgressTrack0.setLearner(relatedLearner0);
}
const relatedLearner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ProgressTrack1 = await ProgressTracks.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (ProgressTrack1?.setLearner) {
await ProgressTrack1.setLearner(relatedLearner1);
}
const relatedLearner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ProgressTrack2 = await ProgressTracks.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (ProgressTrack2?.setLearner) {
await ProgressTrack2.setLearner(relatedLearner2);
}
const relatedLearner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ProgressTrack3 = await ProgressTracks.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (ProgressTrack3?.setLearner) {
await ProgressTrack3.setLearner(relatedLearner3);
}
}
async function associateProgressTrackWithSkill() {
const relatedSkill0 = await Skills.findOne({
offset: Math.floor(Math.random() * (await Skills.count())),
});
const ProgressTrack0 = await ProgressTracks.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (ProgressTrack0?.setSkill) {
await ProgressTrack0.setSkill(relatedSkill0);
}
const relatedSkill1 = await Skills.findOne({
offset: Math.floor(Math.random() * (await Skills.count())),
});
const ProgressTrack1 = await ProgressTracks.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (ProgressTrack1?.setSkill) {
await ProgressTrack1.setSkill(relatedSkill1);
}
const relatedSkill2 = await Skills.findOne({
offset: Math.floor(Math.random() * (await Skills.count())),
});
const ProgressTrack2 = await ProgressTracks.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (ProgressTrack2?.setSkill) {
await ProgressTrack2.setSkill(relatedSkill2);
}
const relatedSkill3 = await Skills.findOne({
offset: Math.floor(Math.random() * (await Skills.count())),
});
const ProgressTrack3 = await ProgressTracks.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (ProgressTrack3?.setSkill) {
await ProgressTrack3.setSkill(relatedSkill3);
}
}
// Similar logic for "relation_many"
module.exports = {
up: async (queryInterface, Sequelize) => {
await Connections.bulkCreate(ConnectionsData);
await ProgressTracks.bulkCreate(ProgressTracksData);
await Skills.bulkCreate(SkillsData);
await Promise.all([
// Similar logic for "relation_many"
await associateConnectionWithLearner(),
await associateConnectionWithMentor(),
await associateProgressTrackWithLearner(),
await associateProgressTrackWithSkill(),
// Similar logic for "relation_many"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('connections', null, {});
await queryInterface.bulkDelete('progress_tracks', null, {});
await queryInterface.bulkDelete('skills', null, {});
},
};