1092 lines
26 KiB
JavaScript
1092 lines
26 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const HumanResources = db.human_resources;
|
|
|
|
const Inventory = db.inventory;
|
|
|
|
const Machinery = db.machinery;
|
|
|
|
const RawMaterials = db.raw_materials;
|
|
|
|
const Suppliers = db.suppliers;
|
|
|
|
const WorkOrders = db.work_orders;
|
|
|
|
const Companies = db.companies;
|
|
|
|
const HumanResourcesData = [
|
|
{
|
|
employee_name: 'John Doe',
|
|
|
|
role: 'Fleet Manager',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
employee_name: 'Jane Smith',
|
|
|
|
role: 'Planner',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
employee_name: 'Emily Johnson',
|
|
|
|
role: 'HR Manager',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
employee_name: 'Michael Brown',
|
|
|
|
role: 'Finance Manager',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
employee_name: 'Sarah Davis',
|
|
|
|
role: 'Procurement Officer',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const InventoryData = [
|
|
{
|
|
item_name: 'Steel Beams',
|
|
|
|
stock_level: 1500,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
item_name: 'Concrete Mix',
|
|
|
|
stock_level: 2000,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
item_name: 'Bricks',
|
|
|
|
stock_level: 5000,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
item_name: 'Pipes',
|
|
|
|
stock_level: 3000,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
item_name: 'Cement',
|
|
|
|
stock_level: 2500,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MachineryData = [
|
|
{
|
|
machine_name: 'Excavator',
|
|
|
|
maintenance_schedule: 'Monthly',
|
|
|
|
last_maintenance: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
machine_name: 'Bulldozer',
|
|
|
|
maintenance_schedule: 'Quarterly',
|
|
|
|
last_maintenance: new Date('2023-09-15T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
machine_name: 'Dump Truck',
|
|
|
|
maintenance_schedule: 'Bi-Annual',
|
|
|
|
last_maintenance: new Date('2023-08-20T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
machine_name: 'Crane',
|
|
|
|
maintenance_schedule: 'Monthly',
|
|
|
|
last_maintenance: new Date('2023-10-10T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
machine_name: 'Loader',
|
|
|
|
maintenance_schedule: 'Quarterly',
|
|
|
|
last_maintenance: new Date('2023-09-05T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const RawMaterialsData = [
|
|
{
|
|
material_name: 'Iron Ore',
|
|
|
|
quantity: 5000,
|
|
|
|
reorder_level: 1000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
material_name: 'Copper',
|
|
|
|
quantity: 3000,
|
|
|
|
reorder_level: 500,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
material_name: 'Limestone',
|
|
|
|
quantity: 7000,
|
|
|
|
reorder_level: 1500,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
material_name: 'Coal',
|
|
|
|
quantity: 10000,
|
|
|
|
reorder_level: 2000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
material_name: 'Gold',
|
|
|
|
quantity: 200,
|
|
|
|
reorder_level: 50,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SuppliersData = [
|
|
{
|
|
supplier_name: 'Global Mining Supplies',
|
|
|
|
contact_info: 'contact@globalmining.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
supplier_name: 'Industrial Metals Inc.',
|
|
|
|
contact_info: 'info@industrialmetals.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
supplier_name: 'Raw Material Co.',
|
|
|
|
contact_info: 'sales@rawmaterialco.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
supplier_name: 'Mining Essentials',
|
|
|
|
contact_info: 'support@miningessentials.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
supplier_name: 'Earth Resources',
|
|
|
|
contact_info: 'hello@earthresources.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const WorkOrdersData = [
|
|
{
|
|
order_number: 'WO-001',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
start_date: new Date('2023-11-01T08:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-05T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
order_number: 'WO-002',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
start_date: new Date('2023-11-06T08:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-10T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
order_number: 'WO-003',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
start_date: new Date('2023-11-11T08:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-15T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
order_number: 'WO-004',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
start_date: new Date('2023-11-16T08:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-20T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
order_number: 'WO-005',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
start_date: new Date('2023-11-21T08:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-25T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CompaniesData = [
|
|
{
|
|
name: 'Trofim Lysenko',
|
|
},
|
|
|
|
{
|
|
name: 'Hans Bethe',
|
|
},
|
|
|
|
{
|
|
name: 'Erwin Schrodinger',
|
|
},
|
|
|
|
{
|
|
name: 'Linus Pauling',
|
|
},
|
|
|
|
{
|
|
name: 'Neils Bohr',
|
|
},
|
|
];
|
|
|
|
// 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 associateHumanResourceWithManager() {
|
|
const relatedManager0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HumanResource0 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (HumanResource0?.setManager) {
|
|
await HumanResource0.setManager(relatedManager0);
|
|
}
|
|
|
|
const relatedManager1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HumanResource1 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (HumanResource1?.setManager) {
|
|
await HumanResource1.setManager(relatedManager1);
|
|
}
|
|
|
|
const relatedManager2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HumanResource2 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (HumanResource2?.setManager) {
|
|
await HumanResource2.setManager(relatedManager2);
|
|
}
|
|
|
|
const relatedManager3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HumanResource3 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (HumanResource3?.setManager) {
|
|
await HumanResource3.setManager(relatedManager3);
|
|
}
|
|
|
|
const relatedManager4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HumanResource4 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (HumanResource4?.setManager) {
|
|
await HumanResource4.setManager(relatedManager4);
|
|
}
|
|
}
|
|
|
|
async function associateHumanResourceWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HumanResource0 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (HumanResource0?.setCompany) {
|
|
await HumanResource0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HumanResource1 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (HumanResource1?.setCompany) {
|
|
await HumanResource1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HumanResource2 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (HumanResource2?.setCompany) {
|
|
await HumanResource2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HumanResource3 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (HumanResource3?.setCompany) {
|
|
await HumanResource3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HumanResource4 = await HumanResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (HumanResource4?.setCompany) {
|
|
await HumanResource4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateInventoryWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Inventory0 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Inventory0?.setCompany) {
|
|
await Inventory0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Inventory1 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Inventory1?.setCompany) {
|
|
await Inventory1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Inventory2 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Inventory2?.setCompany) {
|
|
await Inventory2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Inventory3 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Inventory3?.setCompany) {
|
|
await Inventory3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Inventory4 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Inventory4?.setCompany) {
|
|
await Inventory4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateMachineryWithFleet_manager() {
|
|
const relatedFleet_manager0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Machinery0 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Machinery0?.setFleet_manager) {
|
|
await Machinery0.setFleet_manager(relatedFleet_manager0);
|
|
}
|
|
|
|
const relatedFleet_manager1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Machinery1 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Machinery1?.setFleet_manager) {
|
|
await Machinery1.setFleet_manager(relatedFleet_manager1);
|
|
}
|
|
|
|
const relatedFleet_manager2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Machinery2 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Machinery2?.setFleet_manager) {
|
|
await Machinery2.setFleet_manager(relatedFleet_manager2);
|
|
}
|
|
|
|
const relatedFleet_manager3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Machinery3 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Machinery3?.setFleet_manager) {
|
|
await Machinery3.setFleet_manager(relatedFleet_manager3);
|
|
}
|
|
|
|
const relatedFleet_manager4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Machinery4 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Machinery4?.setFleet_manager) {
|
|
await Machinery4.setFleet_manager(relatedFleet_manager4);
|
|
}
|
|
}
|
|
|
|
async function associateMachineryWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Machinery0 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Machinery0?.setCompany) {
|
|
await Machinery0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Machinery1 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Machinery1?.setCompany) {
|
|
await Machinery1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Machinery2 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Machinery2?.setCompany) {
|
|
await Machinery2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Machinery3 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Machinery3?.setCompany) {
|
|
await Machinery3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Machinery4 = await Machinery.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Machinery4?.setCompany) {
|
|
await Machinery4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateRawMaterialWithSupplier() {
|
|
const relatedSupplier0 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const RawMaterial0 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (RawMaterial0?.setSupplier) {
|
|
await RawMaterial0.setSupplier(relatedSupplier0);
|
|
}
|
|
|
|
const relatedSupplier1 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const RawMaterial1 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (RawMaterial1?.setSupplier) {
|
|
await RawMaterial1.setSupplier(relatedSupplier1);
|
|
}
|
|
|
|
const relatedSupplier2 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const RawMaterial2 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (RawMaterial2?.setSupplier) {
|
|
await RawMaterial2.setSupplier(relatedSupplier2);
|
|
}
|
|
|
|
const relatedSupplier3 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const RawMaterial3 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (RawMaterial3?.setSupplier) {
|
|
await RawMaterial3.setSupplier(relatedSupplier3);
|
|
}
|
|
|
|
const relatedSupplier4 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const RawMaterial4 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (RawMaterial4?.setSupplier) {
|
|
await RawMaterial4.setSupplier(relatedSupplier4);
|
|
}
|
|
}
|
|
|
|
async function associateRawMaterialWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const RawMaterial0 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (RawMaterial0?.setCompany) {
|
|
await RawMaterial0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const RawMaterial1 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (RawMaterial1?.setCompany) {
|
|
await RawMaterial1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const RawMaterial2 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (RawMaterial2?.setCompany) {
|
|
await RawMaterial2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const RawMaterial3 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (RawMaterial3?.setCompany) {
|
|
await RawMaterial3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const RawMaterial4 = await RawMaterials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (RawMaterial4?.setCompany) {
|
|
await RawMaterial4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateSupplierWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Supplier0 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Supplier0?.setCompany) {
|
|
await Supplier0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Supplier1 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Supplier1?.setCompany) {
|
|
await Supplier1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Supplier2 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Supplier2?.setCompany) {
|
|
await Supplier2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Supplier3 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Supplier3?.setCompany) {
|
|
await Supplier3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Supplier4 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Supplier4?.setCompany) {
|
|
await Supplier4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateWorkOrderWithPlanner() {
|
|
const relatedPlanner0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const WorkOrder0 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (WorkOrder0?.setPlanner) {
|
|
await WorkOrder0.setPlanner(relatedPlanner0);
|
|
}
|
|
|
|
const relatedPlanner1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const WorkOrder1 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (WorkOrder1?.setPlanner) {
|
|
await WorkOrder1.setPlanner(relatedPlanner1);
|
|
}
|
|
|
|
const relatedPlanner2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const WorkOrder2 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (WorkOrder2?.setPlanner) {
|
|
await WorkOrder2.setPlanner(relatedPlanner2);
|
|
}
|
|
|
|
const relatedPlanner3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const WorkOrder3 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (WorkOrder3?.setPlanner) {
|
|
await WorkOrder3.setPlanner(relatedPlanner3);
|
|
}
|
|
|
|
const relatedPlanner4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const WorkOrder4 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (WorkOrder4?.setPlanner) {
|
|
await WorkOrder4.setPlanner(relatedPlanner4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateWorkOrderWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const WorkOrder0 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (WorkOrder0?.setCompany) {
|
|
await WorkOrder0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const WorkOrder1 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (WorkOrder1?.setCompany) {
|
|
await WorkOrder1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const WorkOrder2 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (WorkOrder2?.setCompany) {
|
|
await WorkOrder2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const WorkOrder3 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (WorkOrder3?.setCompany) {
|
|
await WorkOrder3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const WorkOrder4 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (WorkOrder4?.setCompany) {
|
|
await WorkOrder4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await HumanResources.bulkCreate(HumanResourcesData);
|
|
|
|
await Inventory.bulkCreate(InventoryData);
|
|
|
|
await Machinery.bulkCreate(MachineryData);
|
|
|
|
await RawMaterials.bulkCreate(RawMaterialsData);
|
|
|
|
await Suppliers.bulkCreate(SuppliersData);
|
|
|
|
await WorkOrders.bulkCreate(WorkOrdersData);
|
|
|
|
await Companies.bulkCreate(CompaniesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithCompany(),
|
|
|
|
await associateHumanResourceWithManager(),
|
|
|
|
await associateHumanResourceWithCompany(),
|
|
|
|
await associateInventoryWithCompany(),
|
|
|
|
await associateMachineryWithFleet_manager(),
|
|
|
|
await associateMachineryWithCompany(),
|
|
|
|
await associateRawMaterialWithSupplier(),
|
|
|
|
await associateRawMaterialWithCompany(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateSupplierWithCompany(),
|
|
|
|
await associateWorkOrderWithPlanner(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateWorkOrderWithCompany(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('human_resources', null, {});
|
|
|
|
await queryInterface.bulkDelete('inventory', null, {});
|
|
|
|
await queryInterface.bulkDelete('machinery', null, {});
|
|
|
|
await queryInterface.bulkDelete('raw_materials', null, {});
|
|
|
|
await queryInterface.bulkDelete('suppliers', null, {});
|
|
|
|
await queryInterface.bulkDelete('work_orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('companies', null, {});
|
|
},
|
|
};
|