890 lines
21 KiB
JavaScript
890 lines
21 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Categories = db.categories;
|
|
|
|
const Clients = db.clients;
|
|
|
|
const Inventory = db.inventory;
|
|
|
|
const OpenStores = db.open_stores;
|
|
|
|
const Products = db.products;
|
|
|
|
const Sales = db.sales;
|
|
|
|
const Openstores = db.openstores;
|
|
|
|
const CategoriesData = [
|
|
{
|
|
name: 'Fruits',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Vegetables',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Dairy',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ClientsData = [
|
|
{
|
|
name: 'Alice Johnson',
|
|
|
|
email: 'alice.johnson@example.com',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Bob Williams',
|
|
|
|
email: 'bob.williams@example.com',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Charlie Brown',
|
|
|
|
email: 'charlie.brown@example.com',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const InventoryData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 100,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 150,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 200,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OpenStoresData = [
|
|
{
|
|
name: 'Green Grocers',
|
|
|
|
address: '123 Green St, Springfield',
|
|
|
|
phone_number: '555-1234',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Fresh Mart',
|
|
|
|
address: '456 Fresh Ave, Metropolis',
|
|
|
|
phone_number: '555-5678',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Daily Needs',
|
|
|
|
address: '789 Daily Rd, Gotham',
|
|
|
|
phone_number: '555-8765',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProductsData = [
|
|
{
|
|
name: 'Apple',
|
|
|
|
price: 1.2,
|
|
|
|
stock_quantity: 100,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Banana',
|
|
|
|
price: 0.5,
|
|
|
|
stock_quantity: 150,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Milk',
|
|
|
|
price: 1.5,
|
|
|
|
stock_quantity: 200,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SalesData = [
|
|
{
|
|
transaction_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
total_amount: 120.5,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
transaction_date: new Date('2023-10-02T11:30:00Z'),
|
|
|
|
total_amount: 75,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
transaction_date: new Date('2023-10-03T14:45:00Z'),
|
|
|
|
total_amount: 200,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OpenstoresData = [
|
|
{
|
|
name: 'John Bardeen',
|
|
},
|
|
|
|
{
|
|
name: 'Louis Victor de Broglie',
|
|
},
|
|
|
|
{
|
|
name: 'Carl Gauss (Karl Friedrich Gauss)',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithOpenstore() {
|
|
const relatedOpenstore0 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setOpenstore) {
|
|
await User0.setOpenstore(relatedOpenstore0);
|
|
}
|
|
|
|
const relatedOpenstore1 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setOpenstore) {
|
|
await User1.setOpenstore(relatedOpenstore1);
|
|
}
|
|
|
|
const relatedOpenstore2 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setOpenstore) {
|
|
await User2.setOpenstore(relatedOpenstore2);
|
|
}
|
|
}
|
|
|
|
async function associateCategoryWithStore() {
|
|
const relatedStore0 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Category0 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Category0?.setStore) {
|
|
await Category0.setStore(relatedStore0);
|
|
}
|
|
|
|
const relatedStore1 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Category1 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Category1?.setStore) {
|
|
await Category1.setStore(relatedStore1);
|
|
}
|
|
|
|
const relatedStore2 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Category2 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Category2?.setStore) {
|
|
await Category2.setStore(relatedStore2);
|
|
}
|
|
}
|
|
|
|
async function associateCategoryWithOpenstore() {
|
|
const relatedOpenstore0 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Category0 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Category0?.setOpenstore) {
|
|
await Category0.setOpenstore(relatedOpenstore0);
|
|
}
|
|
|
|
const relatedOpenstore1 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Category1 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Category1?.setOpenstore) {
|
|
await Category1.setOpenstore(relatedOpenstore1);
|
|
}
|
|
|
|
const relatedOpenstore2 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Category2 = await Categories.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Category2?.setOpenstore) {
|
|
await Category2.setOpenstore(relatedOpenstore2);
|
|
}
|
|
}
|
|
|
|
async function associateClientWithStore() {
|
|
const relatedStore0 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Client0 = await Clients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Client0?.setStore) {
|
|
await Client0.setStore(relatedStore0);
|
|
}
|
|
|
|
const relatedStore1 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Client1 = await Clients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Client1?.setStore) {
|
|
await Client1.setStore(relatedStore1);
|
|
}
|
|
|
|
const relatedStore2 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Client2 = await Clients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Client2?.setStore) {
|
|
await Client2.setStore(relatedStore2);
|
|
}
|
|
}
|
|
|
|
async function associateClientWithOpenstore() {
|
|
const relatedOpenstore0 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Client0 = await Clients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Client0?.setOpenstore) {
|
|
await Client0.setOpenstore(relatedOpenstore0);
|
|
}
|
|
|
|
const relatedOpenstore1 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Client1 = await Clients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Client1?.setOpenstore) {
|
|
await Client1.setOpenstore(relatedOpenstore1);
|
|
}
|
|
|
|
const relatedOpenstore2 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Client2 = await Clients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Client2?.setOpenstore) {
|
|
await Client2.setOpenstore(relatedOpenstore2);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
async function associateInventoryWithStore() {
|
|
const relatedStore0 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Inventory0 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Inventory0?.setStore) {
|
|
await Inventory0.setStore(relatedStore0);
|
|
}
|
|
|
|
const relatedStore1 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Inventory1 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Inventory1?.setStore) {
|
|
await Inventory1.setStore(relatedStore1);
|
|
}
|
|
|
|
const relatedStore2 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Inventory2 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Inventory2?.setStore) {
|
|
await Inventory2.setStore(relatedStore2);
|
|
}
|
|
}
|
|
|
|
async function associateInventoryWithOpenstore() {
|
|
const relatedOpenstore0 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Inventory0 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Inventory0?.setOpenstore) {
|
|
await Inventory0.setOpenstore(relatedOpenstore0);
|
|
}
|
|
|
|
const relatedOpenstore1 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Inventory1 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Inventory1?.setOpenstore) {
|
|
await Inventory1.setOpenstore(relatedOpenstore1);
|
|
}
|
|
|
|
const relatedOpenstore2 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Inventory2 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Inventory2?.setOpenstore) {
|
|
await Inventory2.setOpenstore(relatedOpenstore2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateOpenStoreWithOpenstore() {
|
|
const relatedOpenstore0 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const OpenStore0 = await OpenStores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (OpenStore0?.setOpenstore) {
|
|
await OpenStore0.setOpenstore(relatedOpenstore0);
|
|
}
|
|
|
|
const relatedOpenstore1 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const OpenStore1 = await OpenStores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (OpenStore1?.setOpenstore) {
|
|
await OpenStore1.setOpenstore(relatedOpenstore1);
|
|
}
|
|
|
|
const relatedOpenstore2 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const OpenStore2 = await OpenStores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (OpenStore2?.setOpenstore) {
|
|
await OpenStore2.setOpenstore(relatedOpenstore2);
|
|
}
|
|
}
|
|
|
|
async function associateProductWithCategory() {
|
|
const relatedCategory0 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setCategory) {
|
|
await Product0.setCategory(relatedCategory0);
|
|
}
|
|
|
|
const relatedCategory1 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setCategory) {
|
|
await Product1.setCategory(relatedCategory1);
|
|
}
|
|
|
|
const relatedCategory2 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setCategory) {
|
|
await Product2.setCategory(relatedCategory2);
|
|
}
|
|
}
|
|
|
|
async function associateProductWithStore() {
|
|
const relatedStore0 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setStore) {
|
|
await Product0.setStore(relatedStore0);
|
|
}
|
|
|
|
const relatedStore1 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setStore) {
|
|
await Product1.setStore(relatedStore1);
|
|
}
|
|
|
|
const relatedStore2 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setStore) {
|
|
await Product2.setStore(relatedStore2);
|
|
}
|
|
}
|
|
|
|
async function associateProductWithOpenstore() {
|
|
const relatedOpenstore0 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setOpenstore) {
|
|
await Product0.setOpenstore(relatedOpenstore0);
|
|
}
|
|
|
|
const relatedOpenstore1 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setOpenstore) {
|
|
await Product1.setOpenstore(relatedOpenstore1);
|
|
}
|
|
|
|
const relatedOpenstore2 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setOpenstore) {
|
|
await Product2.setOpenstore(relatedOpenstore2);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithClient() {
|
|
const relatedClient0 = await Clients.findOne({
|
|
offset: Math.floor(Math.random() * (await Clients.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setClient) {
|
|
await Sale0.setClient(relatedClient0);
|
|
}
|
|
|
|
const relatedClient1 = await Clients.findOne({
|
|
offset: Math.floor(Math.random() * (await Clients.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setClient) {
|
|
await Sale1.setClient(relatedClient1);
|
|
}
|
|
|
|
const relatedClient2 = await Clients.findOne({
|
|
offset: Math.floor(Math.random() * (await Clients.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setClient) {
|
|
await Sale2.setClient(relatedClient2);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithStore() {
|
|
const relatedStore0 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setStore) {
|
|
await Sale0.setStore(relatedStore0);
|
|
}
|
|
|
|
const relatedStore1 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setStore) {
|
|
await Sale1.setStore(relatedStore1);
|
|
}
|
|
|
|
const relatedStore2 = await OpenStores.findOne({
|
|
offset: Math.floor(Math.random() * (await OpenStores.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setStore) {
|
|
await Sale2.setStore(relatedStore2);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithOpenstore() {
|
|
const relatedOpenstore0 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setOpenstore) {
|
|
await Sale0.setOpenstore(relatedOpenstore0);
|
|
}
|
|
|
|
const relatedOpenstore1 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setOpenstore) {
|
|
await Sale1.setOpenstore(relatedOpenstore1);
|
|
}
|
|
|
|
const relatedOpenstore2 = await Openstores.findOne({
|
|
offset: Math.floor(Math.random() * (await Openstores.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setOpenstore) {
|
|
await Sale2.setOpenstore(relatedOpenstore2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Categories.bulkCreate(CategoriesData);
|
|
|
|
await Clients.bulkCreate(ClientsData);
|
|
|
|
await Inventory.bulkCreate(InventoryData);
|
|
|
|
await OpenStores.bulkCreate(OpenStoresData);
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
await Sales.bulkCreate(SalesData);
|
|
|
|
await Openstores.bulkCreate(OpenstoresData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOpenstore(),
|
|
|
|
await associateCategoryWithStore(),
|
|
|
|
await associateCategoryWithOpenstore(),
|
|
|
|
await associateClientWithStore(),
|
|
|
|
await associateClientWithOpenstore(),
|
|
|
|
await associateInventoryWithProduct(),
|
|
|
|
await associateInventoryWithStore(),
|
|
|
|
await associateInventoryWithOpenstore(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateOpenStoreWithOpenstore(),
|
|
|
|
await associateProductWithCategory(),
|
|
|
|
await associateProductWithStore(),
|
|
|
|
await associateProductWithOpenstore(),
|
|
|
|
await associateSaleWithClient(),
|
|
|
|
await associateSaleWithStore(),
|
|
|
|
await associateSaleWithOpenstore(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('categories', null, {});
|
|
|
|
await queryInterface.bulkDelete('clients', null, {});
|
|
|
|
await queryInterface.bulkDelete('inventory', null, {});
|
|
|
|
await queryInterface.bulkDelete('open_stores', null, {});
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
|
|
await queryInterface.bulkDelete('sales', null, {});
|
|
|
|
await queryInterface.bulkDelete('openstores', null, {});
|
|
},
|
|
};
|