29726/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-08 21:48:15 +00:00

405 lines
9.2 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const CommunityPosts = db.community_posts;
const Comparisons = db.comparisons;
const GamificationMetrics = db.gamification_metrics;
const Ideas = db.ideas;
const CommunityPostsData = [
{
title: 'How to Validate Your Business Idea',
content: 'Validation is crucial for understanding market needs.',
// type code here for "relation_one" field
posted_at: new Date('2023-10-01T10:00:00Z'),
},
{
title: 'The Importance of a Strong Business Model',
content: 'A solid business model is the foundation of success.',
// type code here for "relation_one" field
posted_at: new Date('2023-10-02T11:00:00Z'),
},
{
title: 'Tips for Optimizing Your Startup',
content: 'Optimization can significantly improve your chances of success.',
// type code here for "relation_one" field
posted_at: new Date('2023-10-03T12:00:00Z'),
},
{
title: 'Launching Your Product Successfully',
content: 'A well-planned launch can make all the difference.',
// type code here for "relation_one" field
posted_at: new Date('2023-10-04T13:00:00Z'),
},
];
const ComparisonsData = [
{
// type code here for "relation_one" field
market_potential_score: 8.5,
feasibility_score: 7,
personal_interest_score: 9,
},
{
// type code here for "relation_one" field
market_potential_score: 7.5,
feasibility_score: 8,
personal_interest_score: 8.5,
},
{
// type code here for "relation_one" field
market_potential_score: 9,
feasibility_score: 7.5,
personal_interest_score: 8,
},
{
// type code here for "relation_one" field
market_potential_score: 8,
feasibility_score: 8.5,
personal_interest_score: 7.5,
},
];
const GamificationMetricsData = [
{
// type code here for "relation_one" field
points: 150,
badge: 'Intermediate',
},
{
// type code here for "relation_one" field
points: 200,
badge: 'Beginner',
},
{
// type code here for "relation_one" field
points: 100,
badge: 'Intermediate',
},
{
// type code here for "relation_one" field
points: 250,
badge: 'Intermediate',
},
];
const IdeasData = [
{
title: 'Eco-Friendly Packaging',
description:
'Develop sustainable packaging solutions for e-commerce businesses.',
stage: 'Ideation',
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
title: 'Online Fitness Platform',
description:
'Create a virtual platform for fitness classes and personal training.',
stage: 'Modeling',
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
title: 'AI-Powered Marketing Tool',
description: 'Build a tool that uses AI to optimize marketing campaigns.',
stage: 'Validation',
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
title: 'Remote Work Solutions',
description: 'Design software to enhance productivity for remote teams.',
stage: 'Validation',
// type code here for "relation_one" field
// type code here for "relation_many" field
},
];
// Similar logic for "relation_many"
async function associateCommunityPostWithAuthor() {
const relatedAuthor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CommunityPost0 = await CommunityPosts.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (CommunityPost0?.setAuthor) {
await CommunityPost0.setAuthor(relatedAuthor0);
}
const relatedAuthor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CommunityPost1 = await CommunityPosts.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (CommunityPost1?.setAuthor) {
await CommunityPost1.setAuthor(relatedAuthor1);
}
const relatedAuthor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CommunityPost2 = await CommunityPosts.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (CommunityPost2?.setAuthor) {
await CommunityPost2.setAuthor(relatedAuthor2);
}
const relatedAuthor3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CommunityPost3 = await CommunityPosts.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (CommunityPost3?.setAuthor) {
await CommunityPost3.setAuthor(relatedAuthor3);
}
}
async function associateComparisonWithIdea() {
const relatedIdea0 = await Ideas.findOne({
offset: Math.floor(Math.random() * (await Ideas.count())),
});
const Comparison0 = await Comparisons.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Comparison0?.setIdea) {
await Comparison0.setIdea(relatedIdea0);
}
const relatedIdea1 = await Ideas.findOne({
offset: Math.floor(Math.random() * (await Ideas.count())),
});
const Comparison1 = await Comparisons.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Comparison1?.setIdea) {
await Comparison1.setIdea(relatedIdea1);
}
const relatedIdea2 = await Ideas.findOne({
offset: Math.floor(Math.random() * (await Ideas.count())),
});
const Comparison2 = await Comparisons.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Comparison2?.setIdea) {
await Comparison2.setIdea(relatedIdea2);
}
const relatedIdea3 = await Ideas.findOne({
offset: Math.floor(Math.random() * (await Ideas.count())),
});
const Comparison3 = await Comparisons.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Comparison3?.setIdea) {
await Comparison3.setIdea(relatedIdea3);
}
}
async function associateGamificationMetricWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GamificationMetric0 = await GamificationMetrics.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (GamificationMetric0?.setUser) {
await GamificationMetric0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GamificationMetric1 = await GamificationMetrics.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (GamificationMetric1?.setUser) {
await GamificationMetric1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GamificationMetric2 = await GamificationMetrics.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (GamificationMetric2?.setUser) {
await GamificationMetric2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GamificationMetric3 = await GamificationMetrics.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (GamificationMetric3?.setUser) {
await GamificationMetric3.setUser(relatedUser3);
}
}
async function associateIdeaWithEntrepreneur() {
const relatedEntrepreneur0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Idea0 = await Ideas.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Idea0?.setEntrepreneur) {
await Idea0.setEntrepreneur(relatedEntrepreneur0);
}
const relatedEntrepreneur1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Idea1 = await Ideas.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Idea1?.setEntrepreneur) {
await Idea1.setEntrepreneur(relatedEntrepreneur1);
}
const relatedEntrepreneur2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Idea2 = await Ideas.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Idea2?.setEntrepreneur) {
await Idea2.setEntrepreneur(relatedEntrepreneur2);
}
const relatedEntrepreneur3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Idea3 = await Ideas.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Idea3?.setEntrepreneur) {
await Idea3.setEntrepreneur(relatedEntrepreneur3);
}
}
// Similar logic for "relation_many"
module.exports = {
up: async (queryInterface, Sequelize) => {
await CommunityPosts.bulkCreate(CommunityPostsData);
await Comparisons.bulkCreate(ComparisonsData);
await GamificationMetrics.bulkCreate(GamificationMetricsData);
await Ideas.bulkCreate(IdeasData);
await Promise.all([
// Similar logic for "relation_many"
await associateCommunityPostWithAuthor(),
await associateComparisonWithIdea(),
await associateGamificationMetricWithUser(),
await associateIdeaWithEntrepreneur(),
// Similar logic for "relation_many"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('community_posts', null, {});
await queryInterface.bulkDelete('comparisons', null, {});
await queryInterface.bulkDelete('gamification_metrics', null, {});
await queryInterface.bulkDelete('ideas', null, {});
},
};