29955/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-17 08:09:02 +00:00

1039 lines
24 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Accountants = db.accountants;
const BusinessOwners = db.business_owners;
const FinanceManagers = db.finance_managers;
const FinancialReports = db.financial_reports;
const GeneralStaff = db.general_staff;
const HrPersonnel = db.hr_personnel;
const Inventory = db.inventory;
const InventoryManagers = db.inventory_managers;
const Invoices = db.invoices;
const ItAdministrators = db.it_administrators;
const LoanRequests = db.loan_requests;
const Payrolls = db.payrolls;
const SalesMarketingTeams = db.sales_marketing_teams;
const AccountantsData = [
{
name: 'Robert Lee',
// type code here for "relation_one" field
},
{
name: 'Linda Harris',
// type code here for "relation_one" field
},
{
name: 'Charles Clark',
// type code here for "relation_one" field
},
{
name: 'Barbara Lewis',
// type code here for "relation_one" field
},
];
const BusinessOwnersData = [
{
name: 'John Doe',
// type code here for "relation_one" field
},
{
name: 'Jane Smith',
// type code here for "relation_one" field
},
{
name: 'Michael Johnson',
// type code here for "relation_one" field
},
{
name: 'Emily Davis',
// type code here for "relation_one" field
},
];
const FinanceManagersData = [
{
name: 'Sarah Wilson',
// type code here for "relation_one" field
},
{
name: 'David Martinez',
// type code here for "relation_one" field
},
{
name: 'Laura Garcia',
// type code here for "relation_one" field
},
{
name: 'James Anderson',
// type code here for "relation_one" field
},
];
const FinancialReportsData = [
{
title: 'Q1 Financial Overview',
generated_at: new Date('2023-01-15T10:00:00Z'),
},
{
title: 'Q2 Financial Overview',
generated_at: new Date('2023-04-15T10:00:00Z'),
},
{
title: 'Q3 Financial Overview',
generated_at: new Date('2023-07-15T10:00:00Z'),
},
{
title: 'Q4 Financial Overview',
generated_at: new Date('2023-10-15T10:00:00Z'),
},
];
const GeneralStaffData = [
{
name: 'Kevin Turner',
// type code here for "relation_one" field
},
{
name: 'Dorothy Phillips',
// type code here for "relation_one" field
},
{
name: 'Jason Campbell',
// type code here for "relation_one" field
},
{
name: 'Sandra Parker',
// type code here for "relation_one" field
},
];
const HrPersonnelData = [
{
name: 'Jessica Hall',
// type code here for "relation_one" field
},
{
name: 'Christopher Allen',
// type code here for "relation_one" field
},
{
name: 'Nancy Young',
// type code here for "relation_one" field
},
{
name: 'Matthew King',
// type code here for "relation_one" field
},
];
const InventoryData = [
{
product_name: 'Laptop',
stock_level: 50,
// type code here for "relation_one" field
},
{
product_name: 'Smartphone',
stock_level: 100,
// type code here for "relation_one" field
},
{
product_name: 'Tablet',
stock_level: 75,
// type code here for "relation_one" field
},
{
product_name: 'Monitor',
stock_level: 30,
// type code here for "relation_one" field
},
];
const InventoryManagersData = [
{
name: 'Steven Scott',
// type code here for "relation_one" field
},
{
name: 'Donna Green',
// type code here for "relation_one" field
},
{
name: 'Paul Adams',
// type code here for "relation_one" field
},
{
name: 'Jennifer Baker',
// type code here for "relation_one" field
},
];
const InvoicesData = [
{
invoice_number: 'INV-001',
issued_date: new Date('2023-01-20T10:00:00Z'),
// type code here for "relation_one" field
},
{
invoice_number: 'INV-002',
issued_date: new Date('2023-02-20T10:00:00Z'),
// type code here for "relation_one" field
},
{
invoice_number: 'INV-003',
issued_date: new Date('2023-03-20T10:00:00Z'),
// type code here for "relation_one" field
},
{
invoice_number: 'INV-004',
issued_date: new Date('2023-04-20T10:00:00Z'),
// type code here for "relation_one" field
},
];
const ItAdministratorsData = [
{
name: 'Amy Edwards',
// type code here for "relation_one" field
},
{
name: 'Gregory Collins',
// type code here for "relation_one" field
},
{
name: 'Rebecca Stewart',
// type code here for "relation_one" field
},
{
name: 'Larry Sanchez',
// type code here for "relation_one" field
},
];
const LoanRequestsData = [
{
request_id: 'LR-001',
amount: 100000,
// type code here for "relation_one" field
},
{
request_id: 'LR-002',
amount: 150000,
// type code here for "relation_one" field
},
{
request_id: 'LR-003',
amount: 200000,
// type code here for "relation_one" field
},
{
request_id: 'LR-004',
amount: 250000,
// type code here for "relation_one" field
},
];
const PayrollsData = [
{
employee_name: 'Alice Johnson',
salary: 50000,
// type code here for "relation_one" field
},
{
employee_name: 'Bob Williams',
salary: 55000,
// type code here for "relation_one" field
},
{
employee_name: 'Catherine Brown',
salary: 60000,
// type code here for "relation_one" field
},
{
employee_name: 'David Jones',
salary: 65000,
// type code here for "relation_one" field
},
];
const SalesMarketingTeamsData = [
{
name: 'George Nelson',
// type code here for "relation_one" field
},
{
name: 'Betty Carter',
// type code here for "relation_one" field
},
{
name: 'Edward Mitchell',
// type code here for "relation_one" field
},
{
name: 'Helen Perez',
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
async function associateAccountantWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Accountant0 = await Accountants.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Accountant0?.setUser) {
await Accountant0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Accountant1 = await Accountants.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Accountant1?.setUser) {
await Accountant1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Accountant2 = await Accountants.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Accountant2?.setUser) {
await Accountant2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Accountant3 = await Accountants.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Accountant3?.setUser) {
await Accountant3.setUser(relatedUser3);
}
}
async function associateBusinessOwnerWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BusinessOwner0 = await BusinessOwners.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (BusinessOwner0?.setUser) {
await BusinessOwner0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BusinessOwner1 = await BusinessOwners.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (BusinessOwner1?.setUser) {
await BusinessOwner1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BusinessOwner2 = await BusinessOwners.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (BusinessOwner2?.setUser) {
await BusinessOwner2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const BusinessOwner3 = await BusinessOwners.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (BusinessOwner3?.setUser) {
await BusinessOwner3.setUser(relatedUser3);
}
}
async function associateFinanceManagerWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const FinanceManager0 = await FinanceManagers.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (FinanceManager0?.setUser) {
await FinanceManager0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const FinanceManager1 = await FinanceManagers.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (FinanceManager1?.setUser) {
await FinanceManager1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const FinanceManager2 = await FinanceManagers.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (FinanceManager2?.setUser) {
await FinanceManager2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const FinanceManager3 = await FinanceManagers.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (FinanceManager3?.setUser) {
await FinanceManager3.setUser(relatedUser3);
}
}
async function associateGeneralStaffWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GeneralStaff0 = await GeneralStaff.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (GeneralStaff0?.setUser) {
await GeneralStaff0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GeneralStaff1 = await GeneralStaff.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (GeneralStaff1?.setUser) {
await GeneralStaff1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GeneralStaff2 = await GeneralStaff.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (GeneralStaff2?.setUser) {
await GeneralStaff2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GeneralStaff3 = await GeneralStaff.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (GeneralStaff3?.setUser) {
await GeneralStaff3.setUser(relatedUser3);
}
}
async function associateHrPersonnelWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const HrPersonnel0 = await HrPersonnel.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (HrPersonnel0?.setUser) {
await HrPersonnel0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const HrPersonnel1 = await HrPersonnel.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (HrPersonnel1?.setUser) {
await HrPersonnel1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const HrPersonnel2 = await HrPersonnel.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (HrPersonnel2?.setUser) {
await HrPersonnel2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const HrPersonnel3 = await HrPersonnel.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (HrPersonnel3?.setUser) {
await HrPersonnel3.setUser(relatedUser3);
}
}
async function associateInventoryWithManaged_by() {
const relatedManaged_by0 = await InventoryManagers.findOne({
offset: Math.floor(Math.random() * (await InventoryManagers.count())),
});
const Inventory0 = await Inventory.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Inventory0?.setManaged_by) {
await Inventory0.setManaged_by(relatedManaged_by0);
}
const relatedManaged_by1 = await InventoryManagers.findOne({
offset: Math.floor(Math.random() * (await InventoryManagers.count())),
});
const Inventory1 = await Inventory.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Inventory1?.setManaged_by) {
await Inventory1.setManaged_by(relatedManaged_by1);
}
const relatedManaged_by2 = await InventoryManagers.findOne({
offset: Math.floor(Math.random() * (await InventoryManagers.count())),
});
const Inventory2 = await Inventory.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Inventory2?.setManaged_by) {
await Inventory2.setManaged_by(relatedManaged_by2);
}
const relatedManaged_by3 = await InventoryManagers.findOne({
offset: Math.floor(Math.random() * (await InventoryManagers.count())),
});
const Inventory3 = await Inventory.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Inventory3?.setManaged_by) {
await Inventory3.setManaged_by(relatedManaged_by3);
}
}
async function associateInventoryManagerWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const InventoryManager0 = await InventoryManagers.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (InventoryManager0?.setUser) {
await InventoryManager0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const InventoryManager1 = await InventoryManagers.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (InventoryManager1?.setUser) {
await InventoryManager1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const InventoryManager2 = await InventoryManagers.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (InventoryManager2?.setUser) {
await InventoryManager2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const InventoryManager3 = await InventoryManagers.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (InventoryManager3?.setUser) {
await InventoryManager3.setUser(relatedUser3);
}
}
async function associateInvoiceWithIssued_by() {
const relatedIssued_by0 = await Accountants.findOne({
offset: Math.floor(Math.random() * (await Accountants.count())),
});
const Invoice0 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Invoice0?.setIssued_by) {
await Invoice0.setIssued_by(relatedIssued_by0);
}
const relatedIssued_by1 = await Accountants.findOne({
offset: Math.floor(Math.random() * (await Accountants.count())),
});
const Invoice1 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Invoice1?.setIssued_by) {
await Invoice1.setIssued_by(relatedIssued_by1);
}
const relatedIssued_by2 = await Accountants.findOne({
offset: Math.floor(Math.random() * (await Accountants.count())),
});
const Invoice2 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Invoice2?.setIssued_by) {
await Invoice2.setIssued_by(relatedIssued_by2);
}
const relatedIssued_by3 = await Accountants.findOne({
offset: Math.floor(Math.random() * (await Accountants.count())),
});
const Invoice3 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Invoice3?.setIssued_by) {
await Invoice3.setIssued_by(relatedIssued_by3);
}
}
async function associateItAdministratorWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ItAdministrator0 = await ItAdministrators.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (ItAdministrator0?.setUser) {
await ItAdministrator0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ItAdministrator1 = await ItAdministrators.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (ItAdministrator1?.setUser) {
await ItAdministrator1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ItAdministrator2 = await ItAdministrators.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (ItAdministrator2?.setUser) {
await ItAdministrator2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ItAdministrator3 = await ItAdministrators.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (ItAdministrator3?.setUser) {
await ItAdministrator3.setUser(relatedUser3);
}
}
async function associateLoanRequestWithApproved_by() {
const relatedApproved_by0 = await BusinessOwners.findOne({
offset: Math.floor(Math.random() * (await BusinessOwners.count())),
});
const LoanRequest0 = await LoanRequests.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (LoanRequest0?.setApproved_by) {
await LoanRequest0.setApproved_by(relatedApproved_by0);
}
const relatedApproved_by1 = await BusinessOwners.findOne({
offset: Math.floor(Math.random() * (await BusinessOwners.count())),
});
const LoanRequest1 = await LoanRequests.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (LoanRequest1?.setApproved_by) {
await LoanRequest1.setApproved_by(relatedApproved_by1);
}
const relatedApproved_by2 = await BusinessOwners.findOne({
offset: Math.floor(Math.random() * (await BusinessOwners.count())),
});
const LoanRequest2 = await LoanRequests.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (LoanRequest2?.setApproved_by) {
await LoanRequest2.setApproved_by(relatedApproved_by2);
}
const relatedApproved_by3 = await BusinessOwners.findOne({
offset: Math.floor(Math.random() * (await BusinessOwners.count())),
});
const LoanRequest3 = await LoanRequests.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (LoanRequest3?.setApproved_by) {
await LoanRequest3.setApproved_by(relatedApproved_by3);
}
}
async function associatePayrollWithProcessed_by() {
const relatedProcessed_by0 = await HrPersonnel.findOne({
offset: Math.floor(Math.random() * (await HrPersonnel.count())),
});
const Payroll0 = await Payrolls.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Payroll0?.setProcessed_by) {
await Payroll0.setProcessed_by(relatedProcessed_by0);
}
const relatedProcessed_by1 = await HrPersonnel.findOne({
offset: Math.floor(Math.random() * (await HrPersonnel.count())),
});
const Payroll1 = await Payrolls.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Payroll1?.setProcessed_by) {
await Payroll1.setProcessed_by(relatedProcessed_by1);
}
const relatedProcessed_by2 = await HrPersonnel.findOne({
offset: Math.floor(Math.random() * (await HrPersonnel.count())),
});
const Payroll2 = await Payrolls.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Payroll2?.setProcessed_by) {
await Payroll2.setProcessed_by(relatedProcessed_by2);
}
const relatedProcessed_by3 = await HrPersonnel.findOne({
offset: Math.floor(Math.random() * (await HrPersonnel.count())),
});
const Payroll3 = await Payrolls.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Payroll3?.setProcessed_by) {
await Payroll3.setProcessed_by(relatedProcessed_by3);
}
}
async function associateSalesMarketingTeamWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SalesMarketingTeam0 = await SalesMarketingTeams.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (SalesMarketingTeam0?.setUser) {
await SalesMarketingTeam0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SalesMarketingTeam1 = await SalesMarketingTeams.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (SalesMarketingTeam1?.setUser) {
await SalesMarketingTeam1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SalesMarketingTeam2 = await SalesMarketingTeams.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (SalesMarketingTeam2?.setUser) {
await SalesMarketingTeam2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SalesMarketingTeam3 = await SalesMarketingTeams.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (SalesMarketingTeam3?.setUser) {
await SalesMarketingTeam3.setUser(relatedUser3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Accountants.bulkCreate(AccountantsData);
await BusinessOwners.bulkCreate(BusinessOwnersData);
await FinanceManagers.bulkCreate(FinanceManagersData);
await FinancialReports.bulkCreate(FinancialReportsData);
await GeneralStaff.bulkCreate(GeneralStaffData);
await HrPersonnel.bulkCreate(HrPersonnelData);
await Inventory.bulkCreate(InventoryData);
await InventoryManagers.bulkCreate(InventoryManagersData);
await Invoices.bulkCreate(InvoicesData);
await ItAdministrators.bulkCreate(ItAdministratorsData);
await LoanRequests.bulkCreate(LoanRequestsData);
await Payrolls.bulkCreate(PayrollsData);
await SalesMarketingTeams.bulkCreate(SalesMarketingTeamsData);
await Promise.all([
// Similar logic for "relation_many"
await associateAccountantWithUser(),
await associateBusinessOwnerWithUser(),
await associateFinanceManagerWithUser(),
await associateGeneralStaffWithUser(),
await associateHrPersonnelWithUser(),
await associateInventoryWithManaged_by(),
await associateInventoryManagerWithUser(),
await associateInvoiceWithIssued_by(),
await associateItAdministratorWithUser(),
await associateLoanRequestWithApproved_by(),
await associatePayrollWithProcessed_by(),
await associateSalesMarketingTeamWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('accountants', null, {});
await queryInterface.bulkDelete('business_owners', null, {});
await queryInterface.bulkDelete('finance_managers', null, {});
await queryInterface.bulkDelete('financial_reports', null, {});
await queryInterface.bulkDelete('general_staff', null, {});
await queryInterface.bulkDelete('hr_personnel', null, {});
await queryInterface.bulkDelete('inventory', null, {});
await queryInterface.bulkDelete('inventory_managers', null, {});
await queryInterface.bulkDelete('invoices', null, {});
await queryInterface.bulkDelete('it_administrators', null, {});
await queryInterface.bulkDelete('loan_requests', null, {});
await queryInterface.bulkDelete('payrolls', null, {});
await queryInterface.bulkDelete('sales_marketing_teams', null, {});
},
};