830 lines
20 KiB
JavaScript
830 lines
20 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const HelpRequests = db.help_requests;
|
|
|
|
const Notifications = db.notifications;
|
|
|
|
const Services = db.services;
|
|
|
|
const Trucks = db.trucks;
|
|
|
|
const Companies = db.companies;
|
|
|
|
const HelpRequestsData = [
|
|
{
|
|
request_date: new Date('2023-10-01T08:30:00Z'),
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
request_date: new Date('2023-10-02T09:00:00Z'),
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
request_date: new Date('2023-10-03T10:15:00Z'),
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
request_date: new Date('2023-10-04T11:45:00Z'),
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
request_date: new Date('2023-10-05T12:30:00Z'),
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const NotificationsData = [
|
|
{
|
|
message: 'New help request received for truck ABC123.',
|
|
|
|
sent_at: new Date('2023-10-01T08:35:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: 'Help request for truck XYZ789 is now in progress.',
|
|
|
|
sent_at: new Date('2023-10-02T09:05:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: 'Help request for truck LMN456 has been completed.',
|
|
|
|
sent_at: new Date('2023-10-03T10:20:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: 'New help request received for truck DEF321.',
|
|
|
|
sent_at: new Date('2023-10-04T11:50:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: 'Help request for truck GHI654 is now in progress.',
|
|
|
|
sent_at: new Date('2023-10-05T12:35:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ServicesData = [
|
|
{
|
|
name: 'Tire Replacement',
|
|
|
|
description: 'Quick and efficient tire replacement service.',
|
|
|
|
price: 150,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Engine Repair',
|
|
|
|
description: 'Comprehensive engine repair and maintenance.',
|
|
|
|
price: 500,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Oil Change',
|
|
|
|
description: 'Regular oil change to keep your truck running smoothly.',
|
|
|
|
price: 75,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Brake Service',
|
|
|
|
description: 'Complete brake inspection and repair.',
|
|
|
|
price: 200,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Battery Replacement',
|
|
|
|
description: 'Fast battery replacement service.',
|
|
|
|
price: 120,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TrucksData = [
|
|
{
|
|
license_plate: 'ABC123',
|
|
|
|
model: 'Volvo FH16',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
license_plate: 'XYZ789',
|
|
|
|
model: 'Scania R450',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
license_plate: 'LMN456',
|
|
|
|
model: 'Mercedes-Benz Actros',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
license_plate: 'DEF321',
|
|
|
|
model: 'MAN TGX',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
license_plate: 'GHI654',
|
|
|
|
model: 'DAF XF',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CompaniesData = [
|
|
{
|
|
name: 'Logistics Co',
|
|
},
|
|
|
|
{
|
|
name: 'Transport Solutions',
|
|
},
|
|
|
|
{
|
|
name: 'Freight Masters',
|
|
},
|
|
|
|
{
|
|
name: 'Haulage Experts',
|
|
},
|
|
|
|
{
|
|
name: 'Cargo Carriers',
|
|
},
|
|
];
|
|
|
|
// 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 associateHelpRequestWithTruck() {
|
|
const relatedTruck0 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const HelpRequest0 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (HelpRequest0?.setTruck) {
|
|
await HelpRequest0.setTruck(relatedTruck0);
|
|
}
|
|
|
|
const relatedTruck1 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const HelpRequest1 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (HelpRequest1?.setTruck) {
|
|
await HelpRequest1.setTruck(relatedTruck1);
|
|
}
|
|
|
|
const relatedTruck2 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const HelpRequest2 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (HelpRequest2?.setTruck) {
|
|
await HelpRequest2.setTruck(relatedTruck2);
|
|
}
|
|
|
|
const relatedTruck3 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const HelpRequest3 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (HelpRequest3?.setTruck) {
|
|
await HelpRequest3.setTruck(relatedTruck3);
|
|
}
|
|
|
|
const relatedTruck4 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const HelpRequest4 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (HelpRequest4?.setTruck) {
|
|
await HelpRequest4.setTruck(relatedTruck4);
|
|
}
|
|
}
|
|
|
|
async function associateHelpRequestWithResponder() {
|
|
const relatedResponder0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HelpRequest0 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (HelpRequest0?.setResponder) {
|
|
await HelpRequest0.setResponder(relatedResponder0);
|
|
}
|
|
|
|
const relatedResponder1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HelpRequest1 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (HelpRequest1?.setResponder) {
|
|
await HelpRequest1.setResponder(relatedResponder1);
|
|
}
|
|
|
|
const relatedResponder2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HelpRequest2 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (HelpRequest2?.setResponder) {
|
|
await HelpRequest2.setResponder(relatedResponder2);
|
|
}
|
|
|
|
const relatedResponder3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HelpRequest3 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (HelpRequest3?.setResponder) {
|
|
await HelpRequest3.setResponder(relatedResponder3);
|
|
}
|
|
|
|
const relatedResponder4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const HelpRequest4 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (HelpRequest4?.setResponder) {
|
|
await HelpRequest4.setResponder(relatedResponder4);
|
|
}
|
|
}
|
|
|
|
async function associateHelpRequestWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HelpRequest0 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (HelpRequest0?.setCompany) {
|
|
await HelpRequest0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HelpRequest1 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (HelpRequest1?.setCompany) {
|
|
await HelpRequest1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HelpRequest2 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (HelpRequest2?.setCompany) {
|
|
await HelpRequest2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HelpRequest3 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (HelpRequest3?.setCompany) {
|
|
await HelpRequest3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const HelpRequest4 = await HelpRequests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (HelpRequest4?.setCompany) {
|
|
await HelpRequest4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateNotificationWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification0 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Notification0?.setUser) {
|
|
await Notification0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification1 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Notification1?.setUser) {
|
|
await Notification1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification2 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Notification2?.setUser) {
|
|
await Notification2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification3 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Notification3?.setUser) {
|
|
await Notification3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification4 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Notification4?.setUser) {
|
|
await Notification4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
async function associateNotificationWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Notification0 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Notification0?.setCompany) {
|
|
await Notification0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Notification1 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Notification1?.setCompany) {
|
|
await Notification1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Notification2 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Notification2?.setCompany) {
|
|
await Notification2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Notification3 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Notification3?.setCompany) {
|
|
await Notification3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Notification4 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Notification4?.setCompany) {
|
|
await Notification4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateServiceWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Service0 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Service0?.setCompany) {
|
|
await Service0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Service1 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Service1?.setCompany) {
|
|
await Service1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Service2 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Service2?.setCompany) {
|
|
await Service2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Service3 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Service3?.setCompany) {
|
|
await Service3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Service4 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Service4?.setCompany) {
|
|
await Service4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateTruckWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck0 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Truck0?.setCompany) {
|
|
await Truck0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck1 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Truck1?.setCompany) {
|
|
await Truck1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck2 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Truck2?.setCompany) {
|
|
await Truck2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck3 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Truck3?.setCompany) {
|
|
await Truck3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck4 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Truck4?.setCompany) {
|
|
await Truck4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateTruckWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck0 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Truck0?.setCompany) {
|
|
await Truck0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck1 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Truck1?.setCompany) {
|
|
await Truck1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck2 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Truck2?.setCompany) {
|
|
await Truck2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck3 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Truck3?.setCompany) {
|
|
await Truck3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Truck4 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Truck4?.setCompany) {
|
|
await Truck4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await HelpRequests.bulkCreate(HelpRequestsData);
|
|
|
|
await Notifications.bulkCreate(NotificationsData);
|
|
|
|
await Services.bulkCreate(ServicesData);
|
|
|
|
await Trucks.bulkCreate(TrucksData);
|
|
|
|
await Companies.bulkCreate(CompaniesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithCompany(),
|
|
|
|
await associateHelpRequestWithTruck(),
|
|
|
|
await associateHelpRequestWithResponder(),
|
|
|
|
await associateHelpRequestWithCompany(),
|
|
|
|
await associateNotificationWithUser(),
|
|
|
|
await associateNotificationWithCompany(),
|
|
|
|
await associateServiceWithCompany(),
|
|
|
|
await associateTruckWithCompany(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateTruckWithCompany(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('help_requests', null, {});
|
|
|
|
await queryInterface.bulkDelete('notifications', null, {});
|
|
|
|
await queryInterface.bulkDelete('services', null, {});
|
|
|
|
await queryInterface.bulkDelete('trucks', null, {});
|
|
|
|
await queryInterface.bulkDelete('companies', null, {});
|
|
},
|
|
};
|