655 lines
13 KiB
JavaScript
655 lines
13 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Appointments = db.appointments;
|
|
|
|
const Customers = db.customers;
|
|
|
|
const Expenses = db.expenses;
|
|
|
|
const Inventory = db.inventory;
|
|
|
|
const Invoices = db.invoices;
|
|
|
|
const JobCards = db.job_cards;
|
|
|
|
const Orders = db.orders;
|
|
|
|
const Vendors = db.vendors;
|
|
|
|
const AppointmentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
appointment_date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
service_description: 'Oil Change',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
appointment_date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
service_description: 'Brake Replacement',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
appointment_date: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
service_description: 'Engine Diagnostics',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
appointment_date: new Date('2023-10-04T12:00:00Z'),
|
|
|
|
service_description: 'Tire Rotation',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
appointment_date: new Date('2023-10-05T13:00:00Z'),
|
|
|
|
service_description: 'Battery Check',
|
|
},
|
|
];
|
|
|
|
const CustomersData = [
|
|
{
|
|
name: 'John Smith',
|
|
|
|
contact_number: '555-1234',
|
|
|
|
email: 'john.smith@example.com',
|
|
},
|
|
|
|
{
|
|
name: 'Jane Doe',
|
|
|
|
contact_number: '555-5678',
|
|
|
|
email: 'jane.doe@example.com',
|
|
},
|
|
|
|
{
|
|
name: 'Michael Brown',
|
|
|
|
contact_number: '555-8765',
|
|
|
|
email: 'michael.brown@example.com',
|
|
},
|
|
|
|
{
|
|
name: 'Emily Davis',
|
|
|
|
contact_number: '555-4321',
|
|
|
|
email: 'emily.davis@example.com',
|
|
},
|
|
|
|
{
|
|
name: 'David Wilson',
|
|
|
|
contact_number: '555-6789',
|
|
|
|
email: 'david.wilson@example.com',
|
|
},
|
|
];
|
|
|
|
const ExpensesData = [
|
|
{
|
|
expense_name: 'Office Supplies',
|
|
|
|
amount: 150,
|
|
|
|
expense_date: new Date('2023-10-01T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
expense_name: 'Utility Bills',
|
|
|
|
amount: 300,
|
|
|
|
expense_date: new Date('2023-10-02T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
expense_name: 'Equipment Maintenance',
|
|
|
|
amount: 500,
|
|
|
|
expense_date: new Date('2023-10-03T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
expense_name: 'Marketing',
|
|
|
|
amount: 250,
|
|
|
|
expense_date: new Date('2023-10-04T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
expense_name: 'Travel Expenses',
|
|
|
|
amount: 100,
|
|
|
|
expense_date: new Date('2023-10-05T00:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const InventoryData = [
|
|
{
|
|
part_name: 'Oil Filter',
|
|
|
|
quantity: 50,
|
|
|
|
price: 5.99,
|
|
},
|
|
|
|
{
|
|
part_name: 'Brake Pads',
|
|
|
|
quantity: 30,
|
|
|
|
price: 25.99,
|
|
},
|
|
|
|
{
|
|
part_name: 'Spark Plugs',
|
|
|
|
quantity: 100,
|
|
|
|
price: 3.49,
|
|
},
|
|
|
|
{
|
|
part_name: 'Tires',
|
|
|
|
quantity: 20,
|
|
|
|
price: 75,
|
|
},
|
|
|
|
{
|
|
part_name: 'Batteries',
|
|
|
|
quantity: 15,
|
|
|
|
price: 120,
|
|
},
|
|
];
|
|
|
|
const InvoicesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
total_amount: 150,
|
|
|
|
invoice_date: new Date('2023-10-01T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
total_amount: 200,
|
|
|
|
invoice_date: new Date('2023-10-02T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
total_amount: 175,
|
|
|
|
invoice_date: new Date('2023-10-03T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
total_amount: 225,
|
|
|
|
invoice_date: new Date('2023-10-04T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
total_amount: 300,
|
|
|
|
invoice_date: new Date('2023-10-05T12:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const JobCardsData = [
|
|
{
|
|
title: 'Oil Change - Honda Civic',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-01T08:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
status: 'in_progress',
|
|
},
|
|
|
|
{
|
|
title: 'Brake Replacement - Toyota Corolla',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-02T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-02T11:30:00Z'),
|
|
|
|
status: 'in_progress',
|
|
},
|
|
|
|
{
|
|
title: 'Engine Diagnostics - Ford Focus',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-03T13:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-03T15:00:00Z'),
|
|
|
|
status: 'completed',
|
|
},
|
|
|
|
{
|
|
title: 'Tire Rotation - BMW 3 Series',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-04T10:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-04T11:00:00Z'),
|
|
|
|
status: 'in_progress',
|
|
},
|
|
|
|
{
|
|
title: 'Battery Check - Audi A4',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-05T14:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-05T15:00:00Z'),
|
|
|
|
status: 'pending',
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
order_type: 'one_time',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_date: new Date('2023-10-02T00:00:00Z'),
|
|
|
|
order_type: 'monthly',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_date: new Date('2023-10-03T00:00:00Z'),
|
|
|
|
order_type: 'weekly',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_date: new Date('2023-10-04T00:00:00Z'),
|
|
|
|
order_type: 'weekly',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_date: new Date('2023-10-05T00:00:00Z'),
|
|
|
|
order_type: 'weekly',
|
|
},
|
|
];
|
|
|
|
const VendorsData = [
|
|
{
|
|
vendor_name: 'Auto Parts Co.',
|
|
|
|
contact_number: '555-1111',
|
|
|
|
email: 'sales@autopartsco.com',
|
|
},
|
|
|
|
{
|
|
vendor_name: 'Mechanic Supplies Inc.',
|
|
|
|
contact_number: '555-2222',
|
|
|
|
email: 'info@mechanicsupplies.com',
|
|
},
|
|
|
|
{
|
|
vendor_name: 'Vehicle Essentials Ltd.',
|
|
|
|
contact_number: '555-3333',
|
|
|
|
email: 'contact@vehicleessentials.com',
|
|
},
|
|
|
|
{
|
|
vendor_name: 'Parts Warehouse',
|
|
|
|
contact_number: '555-4444',
|
|
|
|
email: 'support@partswarehouse.com',
|
|
},
|
|
|
|
{
|
|
vendor_name: 'Car Components Corp.',
|
|
|
|
contact_number: '555-5555',
|
|
|
|
email: 'service@carcomponents.com',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateAppointmentWithCustomer() {
|
|
const relatedCustomer0 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Appointment0 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Appointment0?.setCustomer) {
|
|
await Appointment0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Appointment1 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Appointment1?.setCustomer) {
|
|
await Appointment1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Appointment2 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Appointment2?.setCustomer) {
|
|
await Appointment2.setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Appointment3 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Appointment3?.setCustomer) {
|
|
await Appointment3.setCustomer(relatedCustomer3);
|
|
}
|
|
|
|
const relatedCustomer4 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Appointment4 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Appointment4?.setCustomer) {
|
|
await Appointment4.setCustomer(relatedCustomer4);
|
|
}
|
|
}
|
|
|
|
async function associateInvoiceWithCustomer() {
|
|
const relatedCustomer0 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Invoice0 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Invoice0?.setCustomer) {
|
|
await Invoice0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Invoice1 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Invoice1?.setCustomer) {
|
|
await Invoice1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Invoice2 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Invoice2?.setCustomer) {
|
|
await Invoice2.setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Invoice3 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Invoice3?.setCustomer) {
|
|
await Invoice3.setCustomer(relatedCustomer3);
|
|
}
|
|
|
|
const relatedCustomer4 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Invoice4 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Invoice4?.setCustomer) {
|
|
await Invoice4.setCustomer(relatedCustomer4);
|
|
}
|
|
}
|
|
|
|
async function associateJobCardWithAssigned_mechanic() {
|
|
const relatedAssigned_mechanic0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const JobCard0 = await JobCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (JobCard0?.setAssigned_mechanic) {
|
|
await JobCard0.setAssigned_mechanic(relatedAssigned_mechanic0);
|
|
}
|
|
|
|
const relatedAssigned_mechanic1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const JobCard1 = await JobCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (JobCard1?.setAssigned_mechanic) {
|
|
await JobCard1.setAssigned_mechanic(relatedAssigned_mechanic1);
|
|
}
|
|
|
|
const relatedAssigned_mechanic2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const JobCard2 = await JobCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (JobCard2?.setAssigned_mechanic) {
|
|
await JobCard2.setAssigned_mechanic(relatedAssigned_mechanic2);
|
|
}
|
|
|
|
const relatedAssigned_mechanic3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const JobCard3 = await JobCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (JobCard3?.setAssigned_mechanic) {
|
|
await JobCard3.setAssigned_mechanic(relatedAssigned_mechanic3);
|
|
}
|
|
|
|
const relatedAssigned_mechanic4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const JobCard4 = await JobCards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (JobCard4?.setAssigned_mechanic) {
|
|
await JobCard4.setAssigned_mechanic(relatedAssigned_mechanic4);
|
|
}
|
|
}
|
|
|
|
async function associateOrderWithVendor() {
|
|
const relatedVendor0 = await Vendors.findOne({
|
|
offset: Math.floor(Math.random() * (await Vendors.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setVendor) {
|
|
await Order0.setVendor(relatedVendor0);
|
|
}
|
|
|
|
const relatedVendor1 = await Vendors.findOne({
|
|
offset: Math.floor(Math.random() * (await Vendors.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setVendor) {
|
|
await Order1.setVendor(relatedVendor1);
|
|
}
|
|
|
|
const relatedVendor2 = await Vendors.findOne({
|
|
offset: Math.floor(Math.random() * (await Vendors.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setVendor) {
|
|
await Order2.setVendor(relatedVendor2);
|
|
}
|
|
|
|
const relatedVendor3 = await Vendors.findOne({
|
|
offset: Math.floor(Math.random() * (await Vendors.count())),
|
|
});
|
|
const Order3 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Order3?.setVendor) {
|
|
await Order3.setVendor(relatedVendor3);
|
|
}
|
|
|
|
const relatedVendor4 = await Vendors.findOne({
|
|
offset: Math.floor(Math.random() * (await Vendors.count())),
|
|
});
|
|
const Order4 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Order4?.setVendor) {
|
|
await Order4.setVendor(relatedVendor4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Appointments.bulkCreate(AppointmentsData);
|
|
|
|
await Customers.bulkCreate(CustomersData);
|
|
|
|
await Expenses.bulkCreate(ExpensesData);
|
|
|
|
await Inventory.bulkCreate(InventoryData);
|
|
|
|
await Invoices.bulkCreate(InvoicesData);
|
|
|
|
await JobCards.bulkCreate(JobCardsData);
|
|
|
|
await Orders.bulkCreate(OrdersData);
|
|
|
|
await Vendors.bulkCreate(VendorsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateAppointmentWithCustomer(),
|
|
|
|
await associateInvoiceWithCustomer(),
|
|
|
|
await associateJobCardWithAssigned_mechanic(),
|
|
|
|
await associateOrderWithVendor(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('appointments', null, {});
|
|
|
|
await queryInterface.bulkDelete('customers', null, {});
|
|
|
|
await queryInterface.bulkDelete('expenses', null, {});
|
|
|
|
await queryInterface.bulkDelete('inventory', null, {});
|
|
|
|
await queryInterface.bulkDelete('invoices', null, {});
|
|
|
|
await queryInterface.bulkDelete('job_cards', null, {});
|
|
|
|
await queryInterface.bulkDelete('orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('vendors', null, {});
|
|
},
|
|
};
|