30618/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-10 15:38:42 +00:00

383 lines
8.4 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Answers = db.answers;
const QuestionOptions = db.question_options;
const Questions = db.questions;
const Recommendations = db.recommendations;
const AnswersData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
response: 'Blue',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
response: 'A relaxing beach holiday.',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
response: 'Yes',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
response: 'Remote',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
response: 'Meditation and exercise.',
},
];
const QuestionOptionsData = [
{
text: 'Red',
// type code here for "relation_one" field
},
{
text: 'Blue',
// type code here for "relation_one" field
},
{
text: 'Green',
// type code here for "relation_one" field
},
{
text: 'Office',
// type code here for "relation_one" field
},
{
text: 'Remote',
// type code here for "relation_one" field
},
];
const QuestionsData = [
{
title: 'What is your favorite color?',
type: 'yes_no',
// type code here for "relation_many" field
},
{
title: 'Describe your ideal vacation.',
type: 'multiple_choice',
// type code here for "relation_many" field
},
{
title: 'Do you enjoy outdoor activities?',
type: 'multiple_choice',
// type code here for "relation_many" field
},
{
title: 'What is your preferred work environment?',
type: 'multiple_choice',
// type code here for "relation_many" field
},
{
title: 'How do you handle stress?',
type: 'long_answer',
// type code here for "relation_many" field
},
];
const RecommendationsData = [
{
title: 'Improve Work-Life Balance',
description: 'Consider setting boundaries between work and personal time.',
// type code here for "relation_many" field
},
{
title: 'Explore Outdoor Activities',
description: 'Engage in outdoor activities to boost physical health.',
// type code here for "relation_many" field
},
{
title: 'Consider Remote Work',
description: 'Remote work can offer flexibility and comfort.',
// type code here for "relation_many" field
},
{
title: 'Stress Management Techniques',
description: 'Practice meditation and mindfulness to manage stress.',
// type code here for "relation_many" field
},
{
title: 'Color Preferences',
description:
'Consider using blue tones in your workspace for a calming effect.',
// type code here for "relation_many" field
},
];
// Similar logic for "relation_many"
async function associateAnswerWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Answer0 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Answer0?.setUser) {
await Answer0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Answer1 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Answer1?.setUser) {
await Answer1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Answer2 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Answer2?.setUser) {
await Answer2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Answer3 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Answer3?.setUser) {
await Answer3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Answer4 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Answer4?.setUser) {
await Answer4.setUser(relatedUser4);
}
}
async function associateAnswerWithQuestion() {
const relatedQuestion0 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const Answer0 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Answer0?.setQuestion) {
await Answer0.setQuestion(relatedQuestion0);
}
const relatedQuestion1 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const Answer1 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Answer1?.setQuestion) {
await Answer1.setQuestion(relatedQuestion1);
}
const relatedQuestion2 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const Answer2 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Answer2?.setQuestion) {
await Answer2.setQuestion(relatedQuestion2);
}
const relatedQuestion3 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const Answer3 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Answer3?.setQuestion) {
await Answer3.setQuestion(relatedQuestion3);
}
const relatedQuestion4 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const Answer4 = await Answers.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Answer4?.setQuestion) {
await Answer4.setQuestion(relatedQuestion4);
}
}
async function associateQuestionOptionWithQuestion() {
const relatedQuestion0 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const QuestionOption0 = await QuestionOptions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (QuestionOption0?.setQuestion) {
await QuestionOption0.setQuestion(relatedQuestion0);
}
const relatedQuestion1 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const QuestionOption1 = await QuestionOptions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (QuestionOption1?.setQuestion) {
await QuestionOption1.setQuestion(relatedQuestion1);
}
const relatedQuestion2 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const QuestionOption2 = await QuestionOptions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (QuestionOption2?.setQuestion) {
await QuestionOption2.setQuestion(relatedQuestion2);
}
const relatedQuestion3 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const QuestionOption3 = await QuestionOptions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (QuestionOption3?.setQuestion) {
await QuestionOption3.setQuestion(relatedQuestion3);
}
const relatedQuestion4 = await Questions.findOne({
offset: Math.floor(Math.random() * (await Questions.count())),
});
const QuestionOption4 = await QuestionOptions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (QuestionOption4?.setQuestion) {
await QuestionOption4.setQuestion(relatedQuestion4);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
module.exports = {
up: async (queryInterface, Sequelize) => {
await Answers.bulkCreate(AnswersData);
await QuestionOptions.bulkCreate(QuestionOptionsData);
await Questions.bulkCreate(QuestionsData);
await Recommendations.bulkCreate(RecommendationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateAnswerWithUser(),
await associateAnswerWithQuestion(),
await associateQuestionOptionWithQuestion(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('answers', null, {});
await queryInterface.bulkDelete('question_options', null, {});
await queryInterface.bulkDelete('questions', null, {});
await queryInterface.bulkDelete('recommendations', null, {});
},
};