29679/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-06 21:26:48 +00:00

189 lines
3.9 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Clients = db.clients;
const Inquiries = db.inquiries;
const Reports = db.reports;
const TrainingPrograms = db.training_programs;
const ClientsData = [
{
name: 'Tech Solutions Inc',
contact_email: 'contact@techsolutions.com',
// type code here for "relation_many" field
},
{
name: 'SecureNet Corp',
contact_email: 'info@securenet.com',
// type code here for "relation_many" field
},
{
name: 'CyberGuardians LLC',
contact_email: 'support@cyberguardians.com',
// type code here for "relation_many" field
},
];
const InquiriesData = [
{
subject: 'Interested in a demo',
message: 'We would like to schedule a demo of your platform.',
received_at: new Date('2023-06-01T09:30:00Z'),
},
{
subject: 'Pricing details',
message: 'Could you provide more information on your pricing plans?',
received_at: new Date('2023-06-02T10:00:00Z'),
},
{
subject: 'Technical support',
message: 'We are experiencing issues with the training module.',
received_at: new Date('2023-06-03T11:15:00Z'),
},
];
const ReportsData = [
{
title: 'Q1 Security Overview',
generated_at: new Date('2023-01-15T10:00:00Z'),
// type code here for "relation_one" field
},
{
title: 'Phishing Simulation Results',
generated_at: new Date('2023-02-20T14:30:00Z'),
// type code here for "relation_one" field
},
{
title: 'Annual Compliance Report',
generated_at: new Date('2023-03-10T09:00:00Z'),
// type code here for "relation_one" field
},
];
const TrainingProgramsData = [
{
program_name: 'Advanced Threat Detection',
description:
'Comprehensive training on identifying and mitigating advanced threats.',
// type code here for "relation_many" field
},
{
program_name: 'Phishing Awareness',
description: 'Training to recognize and respond to phishing attempts.',
// type code here for "relation_many" field
},
{
program_name: 'Data Protection Essentials',
description: 'Fundamentals of data protection and privacy.',
// type code here for "relation_many" field
},
];
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateReportWithClient() {
const relatedClient0 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Report0 = await Reports.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Report0?.setClient) {
await Report0.setClient(relatedClient0);
}
const relatedClient1 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Report1 = await Reports.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Report1?.setClient) {
await Report1.setClient(relatedClient1);
}
const relatedClient2 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Report2 = await Reports.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Report2?.setClient) {
await Report2.setClient(relatedClient2);
}
}
// Similar logic for "relation_many"
module.exports = {
up: async (queryInterface, Sequelize) => {
await Clients.bulkCreate(ClientsData);
await Inquiries.bulkCreate(InquiriesData);
await Reports.bulkCreate(ReportsData);
await TrainingPrograms.bulkCreate(TrainingProgramsData);
await Promise.all([
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateReportWithClient(),
// Similar logic for "relation_many"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('clients', null, {});
await queryInterface.bulkDelete('inquiries', null, {});
await queryInterface.bulkDelete('reports', null, {});
await queryInterface.bulkDelete('training_programs', null, {});
},
};