30254/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-28 09:27:26 +00:00

223 lines
4.3 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const AiSuggestions = db.ai_suggestions;
const Designs = db.designs;
const MarketResearches = db.market_researches;
const Tags = db.tags;
const AiSuggestionsData = [
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
];
const DesignsData = [
{
name: 'Sunset T-shirt',
description: 'A vibrant sunset design on a t-shirt.',
clicks: 1500,
sales: 300,
// type code here for "relation_many" field
},
{
name: 'Coffee Mug Art',
description: 'Artistic design for coffee mugs.',
clicks: 1200,
sales: 250,
// type code here for "relation_many" field
},
{
name: 'Abstract Hoodie',
description: 'Abstract patterns on a hoodie.',
clicks: 1800,
sales: 400,
// type code here for "relation_many" field
},
{
name: 'Nature Tote Bag',
description: 'Nature-inspired design for tote bags.',
clicks: 900,
sales: 150,
// type code here for "relation_many" field
},
];
const MarketResearchesData = [
{
product_type: 't-shirt',
research_date: new Date('2023-10-01T00:00:00Z'),
// type code here for "relation_many" field
},
{
product_type: 'coffee mug',
research_date: new Date('2023-09-15T00:00:00Z'),
// type code here for "relation_many" field
},
{
product_type: 'hoodie',
research_date: new Date('2023-08-20T00:00:00Z'),
// type code here for "relation_many" field
},
{
product_type: 'tote bag',
research_date: new Date('2023-07-10T00:00:00Z'),
// type code here for "relation_many" field
},
];
const TagsData = [
{
name: 'trending',
},
{
name: 'popular',
},
{
name: 'bestseller',
},
{
name: 'new',
},
];
// Similar logic for "relation_many"
async function associateAiSuggestionWithDesign() {
const relatedDesign0 = await Designs.findOne({
offset: Math.floor(Math.random() * (await Designs.count())),
});
const AiSuggestion0 = await AiSuggestions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (AiSuggestion0?.setDesign) {
await AiSuggestion0.setDesign(relatedDesign0);
}
const relatedDesign1 = await Designs.findOne({
offset: Math.floor(Math.random() * (await Designs.count())),
});
const AiSuggestion1 = await AiSuggestions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (AiSuggestion1?.setDesign) {
await AiSuggestion1.setDesign(relatedDesign1);
}
const relatedDesign2 = await Designs.findOne({
offset: Math.floor(Math.random() * (await Designs.count())),
});
const AiSuggestion2 = await AiSuggestions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (AiSuggestion2?.setDesign) {
await AiSuggestion2.setDesign(relatedDesign2);
}
const relatedDesign3 = await Designs.findOne({
offset: Math.floor(Math.random() * (await Designs.count())),
});
const AiSuggestion3 = await AiSuggestions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (AiSuggestion3?.setDesign) {
await AiSuggestion3.setDesign(relatedDesign3);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
module.exports = {
up: async (queryInterface, Sequelize) => {
await AiSuggestions.bulkCreate(AiSuggestionsData);
await Designs.bulkCreate(DesignsData);
await MarketResearches.bulkCreate(MarketResearchesData);
await Tags.bulkCreate(TagsData);
await Promise.all([
// Similar logic for "relation_many"
await associateAiSuggestionWithDesign(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('ai_suggestions', null, {});
await queryInterface.bulkDelete('designs', null, {});
await queryInterface.bulkDelete('market_researches', null, {});
await queryInterface.bulkDelete('tags', null, {});
},
};