30997/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-25 16:13:39 +00:00

1047 lines
25 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Activities = db.activities;
const Clients = db.clients;
const Invoices = db.invoices;
const Projects = db.projects;
const Companies = db.companies;
const ActivitiesData = [
{
description: 'Initial project meeting with client',
activity_date: new Date('2023-01-16T10:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'CRM system setup',
activity_date: new Date('2023-02-02T11:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Analytics dashboard design',
activity_date: new Date('2023-03-11T14:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Security audit conducted',
activity_date: new Date('2023-04-21T09:30:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Network performance analysis',
activity_date: new Date('2023-05-06T13:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ClientsData = [
{
name: 'Tech Solutions Inc.',
contact_information: 'tech@solutions.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Legal Eagles LLC',
contact_information: 'contact@legaleagles.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Future Vision Ltd.',
contact_information: 'info@futurevision.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Data Dynamics',
contact_information: 'support@datadynamics.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Secure Systems',
contact_information: 'hello@securesystems.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const InvoicesData = [
{
invoice_number: 'INV-001',
issue_date: new Date('2023-01-20T10:00:00Z'),
amount: 1500,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
invoice_number: 'INV-002',
issue_date: new Date('2023-02-15T10:00:00Z'),
amount: 2500,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
invoice_number: 'INV-003',
issue_date: new Date('2023-03-25T10:00:00Z'),
amount: 3000,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
invoice_number: 'INV-004',
issue_date: new Date('2023-04-30T10:00:00Z'),
amount: 2000,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
invoice_number: 'INV-005',
issue_date: new Date('2023-05-10T10:00:00Z'),
amount: 1800,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ProjectsData = [
{
title: 'AI Development',
start_date: new Date('2023-01-15T09:00:00Z'),
end_date: new Date('2023-06-15T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Legal CRM Implementation',
start_date: new Date('2023-02-01T09:00:00Z'),
end_date: new Date('2023-07-01T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Visionary Analytics',
start_date: new Date('2023-03-10T09:00:00Z'),
end_date: new Date('2023-08-10T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Data Security Upgrade',
start_date: new Date('2023-04-20T09:00:00Z'),
end_date: new Date('2023-09-20T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Network Optimization',
start_date: new Date('2023-05-05T09:00:00Z'),
end_date: new Date('2023-10-05T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const CompaniesData = [
{
name: 'Innovatech',
},
{
name: 'LawTech',
},
{
name: 'Visionary',
},
{
name: 'DataCorp',
},
{
name: 'SecureNet',
},
];
// Similar logic for "relation_many"
async function associateUserWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setCompany) {
await User0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setCompany) {
await User1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setCompany) {
await User2.setCompany(relatedCompany2);
}
const relatedCompany3 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setCompany) {
await User3.setCompany(relatedCompany3);
}
const relatedCompany4 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const User4 = await Users.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (User4?.setCompany) {
await User4.setCompany(relatedCompany4);
}
}
async function associateActivityWithManager() {
const relatedManager0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Activity0?.setManager) {
await Activity0.setManager(relatedManager0);
}
const relatedManager1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Activity1?.setManager) {
await Activity1.setManager(relatedManager1);
}
const relatedManager2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Activity2?.setManager) {
await Activity2.setManager(relatedManager2);
}
const relatedManager3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Activity3?.setManager) {
await Activity3.setManager(relatedManager3);
}
const relatedManager4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Activity4?.setManager) {
await Activity4.setManager(relatedManager4);
}
}
async function associateActivityWithClient() {
const relatedClient0 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Activity0?.setClient) {
await Activity0.setClient(relatedClient0);
}
const relatedClient1 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Activity1?.setClient) {
await Activity1.setClient(relatedClient1);
}
const relatedClient2 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Activity2?.setClient) {
await Activity2.setClient(relatedClient2);
}
const relatedClient3 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Activity3?.setClient) {
await Activity3.setClient(relatedClient3);
}
const relatedClient4 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Activity4?.setClient) {
await Activity4.setClient(relatedClient4);
}
}
async function associateActivityWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Activity0 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Activity0?.setCompany) {
await Activity0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Activity1 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Activity1?.setCompany) {
await Activity1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Activity2 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Activity2?.setCompany) {
await Activity2.setCompany(relatedCompany2);
}
const relatedCompany3 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Activity3 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Activity3?.setCompany) {
await Activity3.setCompany(relatedCompany3);
}
const relatedCompany4 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Activity4 = await Activities.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Activity4?.setCompany) {
await Activity4.setCompany(relatedCompany4);
}
}
async function associateClientWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client0 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Client0?.setCompany) {
await Client0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client1 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Client1?.setCompany) {
await Client1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client2 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Client2?.setCompany) {
await Client2.setCompany(relatedCompany2);
}
const relatedCompany3 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client3 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Client3?.setCompany) {
await Client3.setCompany(relatedCompany3);
}
const relatedCompany4 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client4 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Client4?.setCompany) {
await Client4.setCompany(relatedCompany4);
}
}
async function associateClientWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client0 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Client0?.setCompany) {
await Client0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client1 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Client1?.setCompany) {
await Client1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client2 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Client2?.setCompany) {
await Client2.setCompany(relatedCompany2);
}
const relatedCompany3 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client3 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Client3?.setCompany) {
await Client3.setCompany(relatedCompany3);
}
const relatedCompany4 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Client4 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Client4?.setCompany) {
await Client4.setCompany(relatedCompany4);
}
}
async function associateInvoiceWithClient() {
const relatedClient0 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Invoice0 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Invoice0?.setClient) {
await Invoice0.setClient(relatedClient0);
}
const relatedClient1 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Invoice1 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Invoice1?.setClient) {
await Invoice1.setClient(relatedClient1);
}
const relatedClient2 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Invoice2 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Invoice2?.setClient) {
await Invoice2.setClient(relatedClient2);
}
const relatedClient3 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Invoice3 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Invoice3?.setClient) {
await Invoice3.setClient(relatedClient3);
}
const relatedClient4 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Invoice4 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Invoice4?.setClient) {
await Invoice4.setClient(relatedClient4);
}
}
async function associateInvoiceWithProject() {
const relatedProject0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Invoice0 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Invoice0?.setProject) {
await Invoice0.setProject(relatedProject0);
}
const relatedProject1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Invoice1 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Invoice1?.setProject) {
await Invoice1.setProject(relatedProject1);
}
const relatedProject2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Invoice2 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Invoice2?.setProject) {
await Invoice2.setProject(relatedProject2);
}
const relatedProject3 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Invoice3 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Invoice3?.setProject) {
await Invoice3.setProject(relatedProject3);
}
const relatedProject4 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Invoice4 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Invoice4?.setProject) {
await Invoice4.setProject(relatedProject4);
}
}
async function associateInvoiceWithAccountant() {
const relatedAccountant0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Invoice0 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Invoice0?.setAccountant) {
await Invoice0.setAccountant(relatedAccountant0);
}
const relatedAccountant1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Invoice1 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Invoice1?.setAccountant) {
await Invoice1.setAccountant(relatedAccountant1);
}
const relatedAccountant2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Invoice2 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Invoice2?.setAccountant) {
await Invoice2.setAccountant(relatedAccountant2);
}
const relatedAccountant3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Invoice3 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Invoice3?.setAccountant) {
await Invoice3.setAccountant(relatedAccountant3);
}
const relatedAccountant4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Invoice4 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Invoice4?.setAccountant) {
await Invoice4.setAccountant(relatedAccountant4);
}
}
async function associateInvoiceWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Invoice0 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Invoice0?.setCompany) {
await Invoice0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Invoice1 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Invoice1?.setCompany) {
await Invoice1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Invoice2 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Invoice2?.setCompany) {
await Invoice2.setCompany(relatedCompany2);
}
const relatedCompany3 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Invoice3 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Invoice3?.setCompany) {
await Invoice3.setCompany(relatedCompany3);
}
const relatedCompany4 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Invoice4 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Invoice4?.setCompany) {
await Invoice4.setCompany(relatedCompany4);
}
}
async function associateProjectWithClient() {
const relatedClient0 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Project0 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Project0?.setClient) {
await Project0.setClient(relatedClient0);
}
const relatedClient1 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Project1 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Project1?.setClient) {
await Project1.setClient(relatedClient1);
}
const relatedClient2 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Project2 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Project2?.setClient) {
await Project2.setClient(relatedClient2);
}
const relatedClient3 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Project3 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Project3?.setClient) {
await Project3.setClient(relatedClient3);
}
const relatedClient4 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Project4 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Project4?.setClient) {
await Project4.setClient(relatedClient4);
}
}
// Similar logic for "relation_many"
async function associateProjectWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Project0 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Project0?.setCompany) {
await Project0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Project1 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Project1?.setCompany) {
await Project1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Project2 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Project2?.setCompany) {
await Project2.setCompany(relatedCompany2);
}
const relatedCompany3 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Project3 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Project3?.setCompany) {
await Project3.setCompany(relatedCompany3);
}
const relatedCompany4 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Project4 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Project4?.setCompany) {
await Project4.setCompany(relatedCompany4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Activities.bulkCreate(ActivitiesData);
await Clients.bulkCreate(ClientsData);
await Invoices.bulkCreate(InvoicesData);
await Projects.bulkCreate(ProjectsData);
await Companies.bulkCreate(CompaniesData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithCompany(),
await associateActivityWithManager(),
await associateActivityWithClient(),
await associateActivityWithCompany(),
await associateClientWithCompany(),
await associateClientWithCompany(),
await associateInvoiceWithClient(),
await associateInvoiceWithProject(),
await associateInvoiceWithAccountant(),
await associateInvoiceWithCompany(),
await associateProjectWithClient(),
// Similar logic for "relation_many"
await associateProjectWithCompany(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('activities', null, {});
await queryInterface.bulkDelete('clients', null, {});
await queryInterface.bulkDelete('invoices', null, {});
await queryInterface.bulkDelete('projects', null, {});
await queryInterface.bulkDelete('companies', null, {});
},
};