1431 lines
34 KiB
JavaScript
1431 lines
34 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Customers = db.customers;
|
|
|
|
const Employees = db.employees;
|
|
|
|
const Expenses = db.expenses;
|
|
|
|
const Products = db.products;
|
|
|
|
const Recharges = db.recharges;
|
|
|
|
const Repairs = db.repairs;
|
|
|
|
const Sales = db.sales;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const CustomersData = [
|
|
{
|
|
name: 'John Doe',
|
|
|
|
email: 'john.doe@example.com',
|
|
|
|
phone_number: '1234567890',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Jane Smith',
|
|
|
|
email: 'jane.smith@example.com',
|
|
|
|
phone_number: '0987654321',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Mike Jones',
|
|
|
|
email: 'mike.jones@example.com',
|
|
|
|
phone_number: '1122334455',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Lisa White',
|
|
|
|
email: 'lisa.white@example.com',
|
|
|
|
phone_number: '5566778899',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const EmployeesData = [
|
|
{
|
|
name: 'John Doe',
|
|
|
|
role: 'SuperAdmin',
|
|
|
|
salary: 3000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Jane Smith',
|
|
|
|
role: 'Admin',
|
|
|
|
salary: 4000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Mike Jones',
|
|
|
|
role: 'Technician',
|
|
|
|
salary: 3500,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Lisa White',
|
|
|
|
role: 'Admin',
|
|
|
|
salary: 4500,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ExpensesData = [
|
|
{
|
|
category: 'Rent',
|
|
|
|
amount: 1000,
|
|
|
|
expense_date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
category: 'Utilities',
|
|
|
|
amount: 200,
|
|
|
|
expense_date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
category: 'Marketing',
|
|
|
|
amount: 500,
|
|
|
|
expense_date: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
category: 'Salaries',
|
|
|
|
amount: 3000,
|
|
|
|
expense_date: new Date('2023-10-04T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProductsData = [
|
|
{
|
|
brand: 'Samsung',
|
|
|
|
type: 'accessory',
|
|
|
|
color: 'Black',
|
|
|
|
quantity: 50,
|
|
|
|
buying_price: 300,
|
|
|
|
selling_price: 450,
|
|
|
|
discount: 10,
|
|
|
|
shelf_location: 'A1',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
brand: 'Apple',
|
|
|
|
type: 'phone',
|
|
|
|
color: 'White',
|
|
|
|
quantity: 30,
|
|
|
|
buying_price: 500,
|
|
|
|
selling_price: 700,
|
|
|
|
discount: 15,
|
|
|
|
shelf_location: 'B2',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
brand: 'Sony',
|
|
|
|
type: 'sim',
|
|
|
|
color: 'Red',
|
|
|
|
quantity: 100,
|
|
|
|
buying_price: 20,
|
|
|
|
selling_price: 35,
|
|
|
|
discount: 5,
|
|
|
|
shelf_location: 'C3',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
brand: 'Nokia',
|
|
|
|
type: 'accessory',
|
|
|
|
color: 'Blue',
|
|
|
|
quantity: 200,
|
|
|
|
buying_price: 5,
|
|
|
|
selling_price: 10,
|
|
|
|
discount: 2,
|
|
|
|
shelf_location: 'D4',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const RechargesData = [
|
|
{
|
|
service_type: 'Mobile Recharge',
|
|
|
|
amount: 50,
|
|
|
|
commission: 5,
|
|
|
|
transaction_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
service_type: 'Money Transfer',
|
|
|
|
amount: 200,
|
|
|
|
commission: 10,
|
|
|
|
transaction_date: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
service_type: 'Bill Payment',
|
|
|
|
amount: 100,
|
|
|
|
commission: 2,
|
|
|
|
transaction_date: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
service_type: 'DTH Recharge',
|
|
|
|
amount: 75,
|
|
|
|
commission: 3,
|
|
|
|
transaction_date: new Date('2023-10-04T13:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const RepairsData = [
|
|
{
|
|
repair_id: 'R001',
|
|
|
|
date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
customer_name: 'John Doe',
|
|
|
|
phone_number: '1234567890',
|
|
|
|
device_type: 'Phone',
|
|
|
|
brand: 'Samsung',
|
|
|
|
issue_description: 'Screen cracked',
|
|
|
|
parts_used: 'Screen',
|
|
|
|
repair_cost: 100,
|
|
|
|
status: 'Delivered',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
delivery_date: new Date('2023-10-10T17:00:00Z'),
|
|
|
|
notes: 'Urgent repair',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
repair_id: 'R002',
|
|
|
|
date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
customer_name: 'Jane Smith',
|
|
|
|
phone_number: '0987654321',
|
|
|
|
device_type: 'Phone',
|
|
|
|
brand: 'Apple',
|
|
|
|
issue_description: 'Battery issue',
|
|
|
|
parts_used: 'Battery',
|
|
|
|
repair_cost: 50,
|
|
|
|
status: 'Delivered',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
delivery_date: new Date('2023-10-12T15:00:00Z'),
|
|
|
|
notes: '',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
repair_id: 'R003',
|
|
|
|
date: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
customer_name: 'Mike Jones',
|
|
|
|
phone_number: '1122334455',
|
|
|
|
device_type: 'Accessory',
|
|
|
|
brand: 'Sony',
|
|
|
|
issue_description: 'Cable broken',
|
|
|
|
parts_used: 'Cable',
|
|
|
|
repair_cost: 20,
|
|
|
|
status: 'Received',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
delivery_date: new Date('2023-10-05T13:00:00Z'),
|
|
|
|
notes: '',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
repair_id: 'R004',
|
|
|
|
date: new Date('2023-10-04T12:00:00Z'),
|
|
|
|
customer_name: 'Lisa White',
|
|
|
|
phone_number: '5566778899',
|
|
|
|
device_type: 'SIM',
|
|
|
|
brand: 'Nokia',
|
|
|
|
issue_description: 'Activation issue',
|
|
|
|
parts_used: 'SIM card',
|
|
|
|
repair_cost: 10,
|
|
|
|
status: 'Delivered',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
delivery_date: new Date('2023-10-06T11:00:00Z'),
|
|
|
|
notes: '',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SalesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
discount: 5,
|
|
|
|
sale_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// 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
|
|
|
|
discount: 10,
|
|
|
|
sale_date: new Date('2023-10-02T11:30:00Z'),
|
|
|
|
// 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
|
|
|
|
discount: 2,
|
|
|
|
sale_date: new Date('2023-10-03T14:00:00Z'),
|
|
|
|
// 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
|
|
|
|
discount: 1,
|
|
|
|
sale_date: new Date('2023-10-04T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Tech Solutions Inc.',
|
|
},
|
|
|
|
{
|
|
name: 'Mobile World',
|
|
},
|
|
|
|
{
|
|
name: 'Gadget Hub',
|
|
},
|
|
|
|
{
|
|
name: 'Device Depot',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setOrganization) {
|
|
await User0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setOrganization) {
|
|
await User1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setOrganization) {
|
|
await User2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setOrganization) {
|
|
await User3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateCustomerWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer0 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Customer0?.setOrganization) {
|
|
await Customer0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer1 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Customer1?.setOrganization) {
|
|
await Customer1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer2 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Customer2?.setOrganization) {
|
|
await Customer2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer3 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Customer3?.setOrganization) {
|
|
await Customer3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateCustomerWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer0 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Customer0?.setOrganization) {
|
|
await Customer0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer1 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Customer1?.setOrganization) {
|
|
await Customer1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer2 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Customer2?.setOrganization) {
|
|
await Customer2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer3 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Customer3?.setOrganization) {
|
|
await Customer3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateEmployeeWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Employee0 = await Employees.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Employee0?.setOrganization) {
|
|
await Employee0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Employee1 = await Employees.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Employee1?.setOrganization) {
|
|
await Employee1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Employee2 = await Employees.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Employee2?.setOrganization) {
|
|
await Employee2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Employee3 = await Employees.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Employee3?.setOrganization) {
|
|
await Employee3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateEmployeeWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Employee0 = await Employees.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Employee0?.setOrganization) {
|
|
await Employee0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Employee1 = await Employees.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Employee1?.setOrganization) {
|
|
await Employee1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Employee2 = await Employees.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Employee2?.setOrganization) {
|
|
await Employee2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Employee3 = await Employees.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Employee3?.setOrganization) {
|
|
await Employee3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateExpenseWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Expense0 = await Expenses.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Expense0?.setOrganization) {
|
|
await Expense0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Expense1 = await Expenses.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Expense1?.setOrganization) {
|
|
await Expense1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Expense2 = await Expenses.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Expense2?.setOrganization) {
|
|
await Expense2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Expense3 = await Expenses.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Expense3?.setOrganization) {
|
|
await Expense3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateExpenseWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Expense0 = await Expenses.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Expense0?.setOrganization) {
|
|
await Expense0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Expense1 = await Expenses.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Expense1?.setOrganization) {
|
|
await Expense1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Expense2 = await Expenses.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Expense2?.setOrganization) {
|
|
await Expense2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Expense3 = await Expenses.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Expense3?.setOrganization) {
|
|
await Expense3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateProductWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setOrganization) {
|
|
await Product0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setOrganization) {
|
|
await Product1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setOrganization) {
|
|
await Product2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product3 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Product3?.setOrganization) {
|
|
await Product3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateProductWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setOrganization) {
|
|
await Product0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setOrganization) {
|
|
await Product1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setOrganization) {
|
|
await Product2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product3 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Product3?.setOrganization) {
|
|
await Product3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateRechargeWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Recharge0 = await Recharges.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Recharge0?.setOrganization) {
|
|
await Recharge0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Recharge1 = await Recharges.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Recharge1?.setOrganization) {
|
|
await Recharge1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Recharge2 = await Recharges.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Recharge2?.setOrganization) {
|
|
await Recharge2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Recharge3 = await Recharges.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Recharge3?.setOrganization) {
|
|
await Recharge3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateRechargeWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Recharge0 = await Recharges.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Recharge0?.setOrganization) {
|
|
await Recharge0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Recharge1 = await Recharges.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Recharge1?.setOrganization) {
|
|
await Recharge1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Recharge2 = await Recharges.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Recharge2?.setOrganization) {
|
|
await Recharge2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Recharge3 = await Recharges.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Recharge3?.setOrganization) {
|
|
await Recharge3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateRepairWithTechnician() {
|
|
const relatedTechnician0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Repair0 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Repair0?.setTechnician) {
|
|
await Repair0.setTechnician(relatedTechnician0);
|
|
}
|
|
|
|
const relatedTechnician1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Repair1 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Repair1?.setTechnician) {
|
|
await Repair1.setTechnician(relatedTechnician1);
|
|
}
|
|
|
|
const relatedTechnician2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Repair2 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Repair2?.setTechnician) {
|
|
await Repair2.setTechnician(relatedTechnician2);
|
|
}
|
|
|
|
const relatedTechnician3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Repair3 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Repair3?.setTechnician) {
|
|
await Repair3.setTechnician(relatedTechnician3);
|
|
}
|
|
}
|
|
|
|
async function associateRepairWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Repair0 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Repair0?.setOrganization) {
|
|
await Repair0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Repair1 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Repair1?.setOrganization) {
|
|
await Repair1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Repair2 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Repair2?.setOrganization) {
|
|
await Repair2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Repair3 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Repair3?.setOrganization) {
|
|
await Repair3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateRepairWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Repair0 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Repair0?.setOrganization) {
|
|
await Repair0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Repair1 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Repair1?.setOrganization) {
|
|
await Repair1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Repair2 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Repair2?.setOrganization) {
|
|
await Repair2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Repair3 = await Repairs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Repair3?.setOrganization) {
|
|
await Repair3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithProduct() {
|
|
const relatedProduct0 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setProduct) {
|
|
await Sale0.setProduct(relatedProduct0);
|
|
}
|
|
|
|
const relatedProduct1 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setProduct) {
|
|
await Sale1.setProduct(relatedProduct1);
|
|
}
|
|
|
|
const relatedProduct2 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setProduct) {
|
|
await Sale2.setProduct(relatedProduct2);
|
|
}
|
|
|
|
const relatedProduct3 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Sale3 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Sale3?.setProduct) {
|
|
await Sale3.setProduct(relatedProduct3);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithCustomer() {
|
|
const relatedCustomer0 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setCustomer) {
|
|
await Sale0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setCustomer) {
|
|
await Sale1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setCustomer) {
|
|
await Sale2.setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Sale3 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Sale3?.setCustomer) {
|
|
await Sale3.setCustomer(relatedCustomer3);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setOrganization) {
|
|
await Sale0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setOrganization) {
|
|
await Sale1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setOrganization) {
|
|
await Sale2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale3 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Sale3?.setOrganization) {
|
|
await Sale3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setOrganization) {
|
|
await Sale0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setOrganization) {
|
|
await Sale1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setOrganization) {
|
|
await Sale2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale3 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Sale3?.setOrganization) {
|
|
await Sale3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Customers.bulkCreate(CustomersData);
|
|
|
|
await Employees.bulkCreate(EmployeesData);
|
|
|
|
await Expenses.bulkCreate(ExpensesData);
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
await Recharges.bulkCreate(RechargesData);
|
|
|
|
await Repairs.bulkCreate(RepairsData);
|
|
|
|
await Sales.bulkCreate(SalesData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateCustomerWithOrganization(),
|
|
|
|
await associateCustomerWithOrganization(),
|
|
|
|
await associateEmployeeWithOrganization(),
|
|
|
|
await associateEmployeeWithOrganization(),
|
|
|
|
await associateExpenseWithOrganization(),
|
|
|
|
await associateExpenseWithOrganization(),
|
|
|
|
await associateProductWithOrganization(),
|
|
|
|
await associateProductWithOrganization(),
|
|
|
|
await associateRechargeWithOrganization(),
|
|
|
|
await associateRechargeWithOrganization(),
|
|
|
|
await associateRepairWithTechnician(),
|
|
|
|
await associateRepairWithOrganization(),
|
|
|
|
await associateRepairWithOrganization(),
|
|
|
|
await associateSaleWithProduct(),
|
|
|
|
await associateSaleWithCustomer(),
|
|
|
|
await associateSaleWithOrganization(),
|
|
|
|
await associateSaleWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('customers', null, {});
|
|
|
|
await queryInterface.bulkDelete('employees', null, {});
|
|
|
|
await queryInterface.bulkDelete('expenses', null, {});
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
|
|
await queryInterface.bulkDelete('recharges', null, {});
|
|
|
|
await queryInterface.bulkDelete('repairs', null, {});
|
|
|
|
await queryInterface.bulkDelete('sales', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|