1048 lines
24 KiB
JavaScript
1048 lines
24 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Categories = db.categories;
|
|
|
|
const CoffeeBlends = db.coffee_blends;
|
|
|
|
const Customers = db.customers;
|
|
|
|
const Orders = db.orders;
|
|
|
|
const Payments = db.payments;
|
|
|
|
const Reports = db.reports;
|
|
|
|
const Tenants = db.tenants;
|
|
|
|
const CategoriesData = [
|
|
{
|
|
name: 'Organic',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Fair Trade',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Seasonal',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Single Origin',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Espresso',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CoffeeBlendsData = [
|
|
{
|
|
name: 'Ethiopian Yirgacheffe',
|
|
|
|
price: 12.99,
|
|
|
|
stock_level: 100,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Colombian Supremo',
|
|
|
|
price: 10.99,
|
|
|
|
stock_level: 150,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Espresso Roast',
|
|
|
|
price: 14.99,
|
|
|
|
stock_level: 200,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Guatemalan Antigua',
|
|
|
|
price: 11.99,
|
|
|
|
stock_level: 120,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Sumatra Mandheling',
|
|
|
|
price: 13.99,
|
|
|
|
stock_level: 80,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CustomersData = [
|
|
{
|
|
first_name: 'John',
|
|
|
|
last_name: 'Doe',
|
|
|
|
email: 'john.doe@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Jane',
|
|
|
|
last_name: 'Smith',
|
|
|
|
email: 'jane.smith@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Alice',
|
|
|
|
last_name: 'Johnson',
|
|
|
|
email: 'alice.johnson@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Bob',
|
|
|
|
last_name: 'Brown',
|
|
|
|
email: 'bob.brown@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Charlie',
|
|
|
|
last_name: 'Davis',
|
|
|
|
email: 'charlie.davis@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
order_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
status: 'Shipped',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
order_date: new Date('2023-10-02T11:30:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
status: 'Shipped',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
order_date: new Date('2023-10-03T09:15:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
order_date: new Date('2023-10-04T14:45:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
status: 'Delivered',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
order_date: new Date('2023-10-05T16:20:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
status: 'Delivered',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PaymentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 25.98,
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 10.99,
|
|
|
|
status: 'Refunded',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 25.98,
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 14.99,
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 12.99,
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ReportsData = [
|
|
{
|
|
generated_at: new Date('2023-10-06T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
generated_at: new Date('2023-10-07T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
generated_at: new Date('2023-10-08T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
generated_at: new Date('2023-10-09T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
generated_at: new Date('2023-10-10T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TenantsData = [
|
|
{
|
|
name: 'Coffee House',
|
|
},
|
|
|
|
{
|
|
name: 'Brew Masters',
|
|
},
|
|
|
|
{
|
|
name: 'Java Junction',
|
|
},
|
|
|
|
{
|
|
name: 'Cafe Delight',
|
|
},
|
|
|
|
{
|
|
name: 'Roast & Toast',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setTenant) {
|
|
await User0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setTenant) {
|
|
await User1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setTenant) {
|
|
await User2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setTenant) {
|
|
await User3.setTenant(relatedTenant3);
|
|
}
|
|
|
|
const relatedTenant4 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const User4 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (User4?.setTenant) {
|
|
await User4.setTenant(relatedTenant4);
|
|
}
|
|
}
|
|
|
|
async function associateCategoryWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Category0 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Category0?.setTenant) {
|
|
await Category0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Category1 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Category1?.setTenant) {
|
|
await Category1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Category2 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Category2?.setTenant) {
|
|
await Category2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Category3 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Category3?.setTenant) {
|
|
await Category3.setTenant(relatedTenant3);
|
|
}
|
|
|
|
const relatedTenant4 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Category4 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Category4?.setTenant) {
|
|
await Category4.setTenant(relatedTenant4);
|
|
}
|
|
}
|
|
|
|
async function associateCoffeeBlendWithCategory() {
|
|
const relatedCategory0 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend0 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CoffeeBlend0?.setCategory) {
|
|
await CoffeeBlend0.setCategory(relatedCategory0);
|
|
}
|
|
|
|
const relatedCategory1 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend1 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CoffeeBlend1?.setCategory) {
|
|
await CoffeeBlend1.setCategory(relatedCategory1);
|
|
}
|
|
|
|
const relatedCategory2 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend2 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CoffeeBlend2?.setCategory) {
|
|
await CoffeeBlend2.setCategory(relatedCategory2);
|
|
}
|
|
|
|
const relatedCategory3 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend3 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CoffeeBlend3?.setCategory) {
|
|
await CoffeeBlend3.setCategory(relatedCategory3);
|
|
}
|
|
|
|
const relatedCategory4 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend4 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (CoffeeBlend4?.setCategory) {
|
|
await CoffeeBlend4.setCategory(relatedCategory4);
|
|
}
|
|
}
|
|
|
|
async function associateCoffeeBlendWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const CoffeeBlend0 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CoffeeBlend0?.setTenant) {
|
|
await CoffeeBlend0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const CoffeeBlend1 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CoffeeBlend1?.setTenant) {
|
|
await CoffeeBlend1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const CoffeeBlend2 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CoffeeBlend2?.setTenant) {
|
|
await CoffeeBlend2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const CoffeeBlend3 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CoffeeBlend3?.setTenant) {
|
|
await CoffeeBlend3.setTenant(relatedTenant3);
|
|
}
|
|
|
|
const relatedTenant4 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const CoffeeBlend4 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (CoffeeBlend4?.setTenant) {
|
|
await CoffeeBlend4.setTenant(relatedTenant4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCustomerWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Customer0 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Customer0?.setTenant) {
|
|
await Customer0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Customer1 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Customer1?.setTenant) {
|
|
await Customer1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Customer2 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Customer2?.setTenant) {
|
|
await Customer2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Customer3 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Customer3?.setTenant) {
|
|
await Customer3.setTenant(relatedTenant3);
|
|
}
|
|
|
|
const relatedTenant4 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Customer4 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Customer4?.setTenant) {
|
|
await Customer4.setTenant(relatedTenant4);
|
|
}
|
|
}
|
|
|
|
async function associateOrderWithCustomer() {
|
|
const relatedCustomer0 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setCustomer) {
|
|
await Order0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setCustomer) {
|
|
await Order1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setCustomer) {
|
|
await Order2.setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order3 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Order3?.setCustomer) {
|
|
await Order3.setCustomer(relatedCustomer3);
|
|
}
|
|
|
|
const relatedCustomer4 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order4 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Order4?.setCustomer) {
|
|
await Order4.setCustomer(relatedCustomer4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateOrderWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setTenant) {
|
|
await Order0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setTenant) {
|
|
await Order1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setTenant) {
|
|
await Order2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Order3 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Order3?.setTenant) {
|
|
await Order3.setTenant(relatedTenant3);
|
|
}
|
|
|
|
const relatedTenant4 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Order4 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Order4?.setTenant) {
|
|
await Order4.setTenant(relatedTenant4);
|
|
}
|
|
}
|
|
|
|
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 associatePaymentWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setTenant) {
|
|
await Payment0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setTenant) {
|
|
await Payment1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setTenant) {
|
|
await Payment2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Payment3 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Payment3?.setTenant) {
|
|
await Payment3.setTenant(relatedTenant3);
|
|
}
|
|
|
|
const relatedTenant4 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Payment4 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Payment4?.setTenant) {
|
|
await Payment4.setTenant(relatedTenant4);
|
|
}
|
|
}
|
|
|
|
async function associateReportWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report0 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Report0?.setTenant) {
|
|
await Report0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report1 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Report1?.setTenant) {
|
|
await Report1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report2 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Report2?.setTenant) {
|
|
await Report2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report3 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Report3?.setTenant) {
|
|
await Report3.setTenant(relatedTenant3);
|
|
}
|
|
|
|
const relatedTenant4 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report4 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Report4?.setTenant) {
|
|
await Report4.setTenant(relatedTenant4);
|
|
}
|
|
}
|
|
|
|
async function associateReportWithTenant() {
|
|
const relatedTenant0 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report0 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Report0?.setTenant) {
|
|
await Report0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report1 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Report1?.setTenant) {
|
|
await Report1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report2 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Report2?.setTenant) {
|
|
await Report2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report3 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Report3?.setTenant) {
|
|
await Report3.setTenant(relatedTenant3);
|
|
}
|
|
|
|
const relatedTenant4 = await Tenants.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenants.count())),
|
|
});
|
|
const Report4 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Report4?.setTenant) {
|
|
await Report4.setTenant(relatedTenant4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Categories.bulkCreate(CategoriesData);
|
|
|
|
await CoffeeBlends.bulkCreate(CoffeeBlendsData);
|
|
|
|
await Customers.bulkCreate(CustomersData);
|
|
|
|
await Orders.bulkCreate(OrdersData);
|
|
|
|
await Payments.bulkCreate(PaymentsData);
|
|
|
|
await Reports.bulkCreate(ReportsData);
|
|
|
|
await Tenants.bulkCreate(TenantsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithTenant(),
|
|
|
|
await associateCategoryWithTenant(),
|
|
|
|
await associateCoffeeBlendWithCategory(),
|
|
|
|
await associateCoffeeBlendWithTenant(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCustomerWithTenant(),
|
|
|
|
await associateOrderWithCustomer(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateOrderWithTenant(),
|
|
|
|
await associatePaymentWithOrder(),
|
|
|
|
await associatePaymentWithTenant(),
|
|
|
|
await associateReportWithTenant(),
|
|
|
|
await associateReportWithTenant(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('categories', null, {});
|
|
|
|
await queryInterface.bulkDelete('coffee_blends', null, {});
|
|
|
|
await queryInterface.bulkDelete('customers', null, {});
|
|
|
|
await queryInterface.bulkDelete('orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('payments', null, {});
|
|
|
|
await queryInterface.bulkDelete('reports', null, {});
|
|
|
|
await queryInterface.bulkDelete('tenants', null, {});
|
|
},
|
|
};
|