1188 lines
28 KiB
JavaScript
1188 lines
28 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Complaints = db.complaints;
|
|
|
|
const Inventory = db.inventory;
|
|
|
|
const Payments = db.payments;
|
|
|
|
const Orders = db.orders;
|
|
|
|
const Products = db.products;
|
|
|
|
const Companies = db.companies;
|
|
|
|
const ComplaintsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
details: 'Screen flickering issue',
|
|
|
|
status: 'New',
|
|
|
|
reported_date: new Date('2023-10-06T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
details: 'Battery not charging',
|
|
|
|
status: 'InProgress',
|
|
|
|
reported_date: new Date('2023-10-07T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
details: 'Left earbud not working',
|
|
|
|
status: 'InProgress',
|
|
|
|
reported_date: new Date('2023-10-08T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
details: 'Strap broken',
|
|
|
|
status: 'Resolved',
|
|
|
|
reported_date: new Date('2023-10-09T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
details: 'Touchscreen unresponsive',
|
|
|
|
status: 'Resolved',
|
|
|
|
reported_date: new Date('2023-10-10T13:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const InventoryData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
stock_level: 150,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
stock_level: 80,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
stock_level: 300,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
stock_level: 120,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
stock_level: 200,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PaymentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 34999.5,
|
|
|
|
payment_date: new Date('2023-10-11T15:00:00Z'),
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 25999.8,
|
|
|
|
payment_date: new Date('2023-10-12T16:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 19999,
|
|
|
|
payment_date: new Date('2023-10-13T17:00:00Z'),
|
|
|
|
status: 'Failed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 8999.7,
|
|
|
|
payment_date: new Date('2023-10-14T18:00:00Z'),
|
|
|
|
status: 'Failed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 19999.6,
|
|
|
|
payment_date: new Date('2023-10-15T19:00:00Z'),
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 50,
|
|
|
|
total_price: 34999.5,
|
|
|
|
order_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
status: 'Shipped',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 20,
|
|
|
|
total_price: 25999.8,
|
|
|
|
order_date: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
status: 'Delivered',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 100,
|
|
|
|
total_price: 19999,
|
|
|
|
order_date: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
status: 'Shipped',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 30,
|
|
|
|
total_price: 8999.7,
|
|
|
|
order_date: new Date('2023-10-04T13: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
|
|
|
|
quantity: 40,
|
|
|
|
total_price: 19999.6,
|
|
|
|
order_date: new Date('2023-10-05T14:00:00Z'),
|
|
|
|
status: 'Approved',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProductsData = [
|
|
{
|
|
name: 'Smartphone X',
|
|
|
|
description: 'Latest model with advanced features',
|
|
|
|
price: 699.99,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Laptop Pro',
|
|
|
|
description: 'High-performance laptop for professionals',
|
|
|
|
price: 1299.99,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Wireless Earbuds',
|
|
|
|
description: 'Noise-cancelling wireless earbuds',
|
|
|
|
price: 199.99,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Smartwatch',
|
|
|
|
description: 'Feature-rich smartwatch with health tracking',
|
|
|
|
price: 299.99,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Tablet Plus',
|
|
|
|
description: 'Lightweight tablet with high-resolution display',
|
|
|
|
price: 499.99,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CompaniesData = [
|
|
{
|
|
name: 'Tech Solutions Inc.',
|
|
},
|
|
|
|
{
|
|
name: 'Innovatech Corp.',
|
|
},
|
|
|
|
{
|
|
name: 'Future Enterprises',
|
|
},
|
|
|
|
{
|
|
name: 'Global Tech Partners',
|
|
},
|
|
|
|
{
|
|
name: 'NextGen Solutions',
|
|
},
|
|
];
|
|
|
|
// 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 associateComplaintWithProduct() {
|
|
const relatedProduct0 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Complaint0 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Complaint0?.setProduct) {
|
|
await Complaint0.setProduct(relatedProduct0);
|
|
}
|
|
|
|
const relatedProduct1 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Complaint1 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Complaint1?.setProduct) {
|
|
await Complaint1.setProduct(relatedProduct1);
|
|
}
|
|
|
|
const relatedProduct2 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Complaint2 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Complaint2?.setProduct) {
|
|
await Complaint2.setProduct(relatedProduct2);
|
|
}
|
|
|
|
const relatedProduct3 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Complaint3 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Complaint3?.setProduct) {
|
|
await Complaint3.setProduct(relatedProduct3);
|
|
}
|
|
|
|
const relatedProduct4 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Complaint4 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Complaint4?.setProduct) {
|
|
await Complaint4.setProduct(relatedProduct4);
|
|
}
|
|
}
|
|
|
|
async function associateComplaintWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint0 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Complaint0?.setCompany) {
|
|
await Complaint0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint1 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Complaint1?.setCompany) {
|
|
await Complaint1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint2 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Complaint2?.setCompany) {
|
|
await Complaint2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint3 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Complaint3?.setCompany) {
|
|
await Complaint3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint4 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Complaint4?.setCompany) {
|
|
await Complaint4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateComplaintWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint0 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Complaint0?.setCompany) {
|
|
await Complaint0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint1 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Complaint1?.setCompany) {
|
|
await Complaint1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint2 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Complaint2?.setCompany) {
|
|
await Complaint2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint3 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Complaint3?.setCompany) {
|
|
await Complaint3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Complaint4 = await Complaints.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Complaint4?.setCompany) {
|
|
await Complaint4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateInventoryWithProduct() {
|
|
const relatedProduct0 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Inventory0 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Inventory0?.setProduct) {
|
|
await Inventory0.setProduct(relatedProduct0);
|
|
}
|
|
|
|
const relatedProduct1 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Inventory1 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Inventory1?.setProduct) {
|
|
await Inventory1.setProduct(relatedProduct1);
|
|
}
|
|
|
|
const relatedProduct2 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Inventory2 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Inventory2?.setProduct) {
|
|
await Inventory2.setProduct(relatedProduct2);
|
|
}
|
|
|
|
const relatedProduct3 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Inventory3 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Inventory3?.setProduct) {
|
|
await Inventory3.setProduct(relatedProduct3);
|
|
}
|
|
|
|
const relatedProduct4 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Inventory4 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Inventory4?.setProduct) {
|
|
await Inventory4.setProduct(relatedProduct4);
|
|
}
|
|
}
|
|
|
|
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 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 associatePaymentWithOrder() {
|
|
const relatedOrder0 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setOrder) {
|
|
await Payment0.setOrder(relatedOrder0);
|
|
}
|
|
|
|
const relatedOrder1 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setOrder) {
|
|
await Payment1.setOrder(relatedOrder1);
|
|
}
|
|
|
|
const relatedOrder2 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setOrder) {
|
|
await Payment2.setOrder(relatedOrder2);
|
|
}
|
|
|
|
const relatedOrder3 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment3 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Payment3?.setOrder) {
|
|
await Payment3.setOrder(relatedOrder3);
|
|
}
|
|
|
|
const relatedOrder4 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment4 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Payment4?.setOrder) {
|
|
await Payment4.setOrder(relatedOrder4);
|
|
}
|
|
}
|
|
|
|
async function associatePaymentWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setCompany) {
|
|
await Payment0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setCompany) {
|
|
await Payment1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setCompany) {
|
|
await Payment2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Payment3 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Payment3?.setCompany) {
|
|
await Payment3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Payment4 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Payment4?.setCompany) {
|
|
await Payment4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateOrderWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setCompany) {
|
|
await Order0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setCompany) {
|
|
await Order1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setCompany) {
|
|
await Order2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order3 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Order3?.setCompany) {
|
|
await Order3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order4 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Order4?.setCompany) {
|
|
await Order4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
async function associateOrderWithProduct() {
|
|
const relatedProduct0 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setProduct) {
|
|
await Order0.setProduct(relatedProduct0);
|
|
}
|
|
|
|
const relatedProduct1 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setProduct) {
|
|
await Order1.setProduct(relatedProduct1);
|
|
}
|
|
|
|
const relatedProduct2 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setProduct) {
|
|
await Order2.setProduct(relatedProduct2);
|
|
}
|
|
|
|
const relatedProduct3 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Order3 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Order3?.setProduct) {
|
|
await Order3.setProduct(relatedProduct3);
|
|
}
|
|
|
|
const relatedProduct4 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Order4 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Order4?.setProduct) {
|
|
await Order4.setProduct(relatedProduct4);
|
|
}
|
|
}
|
|
|
|
async function associateOrderWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setCompany) {
|
|
await Order0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setCompany) {
|
|
await Order1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setCompany) {
|
|
await Order2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order3 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Order3?.setCompany) {
|
|
await Order3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Order4 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Order4?.setCompany) {
|
|
await Order4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateProductWithCompany() {
|
|
const relatedCompany0 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setCompany) {
|
|
await Product0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setCompany) {
|
|
await Product1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setCompany) {
|
|
await Product2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Product3 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Product3?.setCompany) {
|
|
await Product3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Companies.findOne({
|
|
offset: Math.floor(Math.random() * (await Companies.count())),
|
|
});
|
|
const Product4 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Product4?.setCompany) {
|
|
await Product4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Complaints.bulkCreate(ComplaintsData);
|
|
|
|
await Inventory.bulkCreate(InventoryData);
|
|
|
|
await Payments.bulkCreate(PaymentsData);
|
|
|
|
await Orders.bulkCreate(OrdersData);
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
await Companies.bulkCreate(CompaniesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithCompany(),
|
|
|
|
await associateComplaintWithProduct(),
|
|
|
|
await associateComplaintWithCompany(),
|
|
|
|
await associateComplaintWithCompany(),
|
|
|
|
await associateInventoryWithProduct(),
|
|
|
|
await associateInventoryWithCompany(),
|
|
|
|
await associateInventoryWithCompany(),
|
|
|
|
await associatePaymentWithOrder(),
|
|
|
|
await associatePaymentWithCompany(),
|
|
|
|
await associateOrderWithCompany(),
|
|
|
|
await associateOrderWithProduct(),
|
|
|
|
await associateOrderWithCompany(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateProductWithCompany(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('complaints', null, {});
|
|
|
|
await queryInterface.bulkDelete('inventory', null, {});
|
|
|
|
await queryInterface.bulkDelete('payments', null, {});
|
|
|
|
await queryInterface.bulkDelete('orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
|
|
await queryInterface.bulkDelete('companies', null, {});
|
|
},
|
|
};
|