1672 lines
31 KiB
JavaScript
1672 lines
31 KiB
JavaScript
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Shops = db.shops;
|
|
|
|
const Products = db.products;
|
|
|
|
const Transactions = db.transactions;
|
|
|
|
const TransactionItems = db.transaction_items;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ShopsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Tirta Ornamental Fish",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"owner_name": "Hendra Wijaya",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"phone": "6281387654321",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"address": "Blok A No 12, Pasar Ikan Hias Parung, Bogor",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Parung Aquatic Center",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"owner_name": "Lina Susanti",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"phone": "6281299900012",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"address": "Blok B No 5, Pasar Ikan Hias Parung, Bogor",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Nusantara Koi House",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"owner_name": "Fajar Nugroho",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"phone": "6281312345678",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"address": "Blok C No 2, Pasar Ikan Hias Parung, Bogor",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Biru Laut Aquascape",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"owner_name": "Maya Lestari",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"phone": "6281212348899",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"address": "Blok D No 9, Pasar Ikan Hias Parung, Bogor",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Sinar Guppy Farm",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"owner_name": "Rudi Hartono",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"phone": "6281570011223",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"address": "Blok E No 3, Pasar Ikan Hias Parung, Bogor",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const ProductsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Guppy Premium Mix",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "Guppy",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"price": 15000.5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"stock": 120,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"min_stock": 20,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Koi Kohaku Size M",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "Koi",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"price": 180000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"stock": 25,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"min_stock": 5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Neon Tetra",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "Tetra",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"price": 6000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"stock": 300,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"min_stock": 50,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Ikan Cupang Halfmoon",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "Betta",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"price": 45000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"stock": 60,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"min_stock": 10,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Udang Cherry Red",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "Shrimp",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"price": 8000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"stock": 200,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"min_stock": 30,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const TransactionsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"transaction_code": "TRX-2026-0001",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"transaction_at": new Date('2026-02-10T10:15:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "draft",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"total_amount": 75002.5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"notes": "Walk-in customer purchase",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"transaction_code": "TRX-2026-0002",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"transaction_at": new Date('2026-02-11T08:40:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "draft",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"total_amount": 54000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"notes": "Morning sale",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"transaction_code": "TRX-2026-0003",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"transaction_at": new Date('2026-02-12T13:05:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "completed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"total_amount": 180000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"notes": "Single item purchase",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"transaction_code": "TRX-2026-0004",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"transaction_at": new Date('2026-02-13T15:20:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "cancelled",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"total_amount": 160000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"notes": "Aquascape livestock sale",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"transaction_code": "TRX-2026-0005",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"transaction_at": new Date('2026-02-14T11:30:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "draft",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"total_amount": 90000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"notes": "Weekend traffic",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const TransactionItemsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"quantity": 5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"unit_price": 15000.5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"line_total": 75002.5,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"quantity": 9,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"unit_price": 6000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"line_total": 54000,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"quantity": 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"unit_price": 180000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"line_total": 180000,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"quantity": 20,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"unit_price": 8000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"line_total": 160000,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"quantity": 2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"unit_price": 45000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"line_total": 90000,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateProductWithShop() {
|
|
|
|
const relatedShop0 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Product0?.setShop)
|
|
{
|
|
await
|
|
Product0.
|
|
setShop(relatedShop0);
|
|
}
|
|
|
|
const relatedShop1 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Product1?.setShop)
|
|
{
|
|
await
|
|
Product1.
|
|
setShop(relatedShop1);
|
|
}
|
|
|
|
const relatedShop2 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Product2?.setShop)
|
|
{
|
|
await
|
|
Product2.
|
|
setShop(relatedShop2);
|
|
}
|
|
|
|
const relatedShop3 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Product3 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Product3?.setShop)
|
|
{
|
|
await
|
|
Product3.
|
|
setShop(relatedShop3);
|
|
}
|
|
|
|
const relatedShop4 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Product4 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4
|
|
});
|
|
if (Product4?.setShop)
|
|
{
|
|
await
|
|
Product4.
|
|
setShop(relatedShop4);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateTransactionWithShop() {
|
|
|
|
const relatedShop0 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Transaction0 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Transaction0?.setShop)
|
|
{
|
|
await
|
|
Transaction0.
|
|
setShop(relatedShop0);
|
|
}
|
|
|
|
const relatedShop1 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Transaction1 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Transaction1?.setShop)
|
|
{
|
|
await
|
|
Transaction1.
|
|
setShop(relatedShop1);
|
|
}
|
|
|
|
const relatedShop2 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Transaction2 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Transaction2?.setShop)
|
|
{
|
|
await
|
|
Transaction2.
|
|
setShop(relatedShop2);
|
|
}
|
|
|
|
const relatedShop3 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Transaction3 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Transaction3?.setShop)
|
|
{
|
|
await
|
|
Transaction3.
|
|
setShop(relatedShop3);
|
|
}
|
|
|
|
const relatedShop4 = await Shops.findOne({
|
|
offset: Math.floor(Math.random() * (await Shops.count())),
|
|
});
|
|
const Transaction4 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4
|
|
});
|
|
if (Transaction4?.setShop)
|
|
{
|
|
await
|
|
Transaction4.
|
|
setShop(relatedShop4);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateTransactionWithCashier() {
|
|
|
|
const relatedCashier0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Transaction0 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Transaction0?.setCashier)
|
|
{
|
|
await
|
|
Transaction0.
|
|
setCashier(relatedCashier0);
|
|
}
|
|
|
|
const relatedCashier1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Transaction1 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Transaction1?.setCashier)
|
|
{
|
|
await
|
|
Transaction1.
|
|
setCashier(relatedCashier1);
|
|
}
|
|
|
|
const relatedCashier2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Transaction2 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Transaction2?.setCashier)
|
|
{
|
|
await
|
|
Transaction2.
|
|
setCashier(relatedCashier2);
|
|
}
|
|
|
|
const relatedCashier3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Transaction3 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Transaction3?.setCashier)
|
|
{
|
|
await
|
|
Transaction3.
|
|
setCashier(relatedCashier3);
|
|
}
|
|
|
|
const relatedCashier4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Transaction4 = await Transactions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4
|
|
});
|
|
if (Transaction4?.setCashier)
|
|
{
|
|
await
|
|
Transaction4.
|
|
setCashier(relatedCashier4);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateTransactionItemWithTransaction() {
|
|
|
|
const relatedTransaction0 = await Transactions.findOne({
|
|
offset: Math.floor(Math.random() * (await Transactions.count())),
|
|
});
|
|
const TransactionItem0 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (TransactionItem0?.setTransaction)
|
|
{
|
|
await
|
|
TransactionItem0.
|
|
setTransaction(relatedTransaction0);
|
|
}
|
|
|
|
const relatedTransaction1 = await Transactions.findOne({
|
|
offset: Math.floor(Math.random() * (await Transactions.count())),
|
|
});
|
|
const TransactionItem1 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (TransactionItem1?.setTransaction)
|
|
{
|
|
await
|
|
TransactionItem1.
|
|
setTransaction(relatedTransaction1);
|
|
}
|
|
|
|
const relatedTransaction2 = await Transactions.findOne({
|
|
offset: Math.floor(Math.random() * (await Transactions.count())),
|
|
});
|
|
const TransactionItem2 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (TransactionItem2?.setTransaction)
|
|
{
|
|
await
|
|
TransactionItem2.
|
|
setTransaction(relatedTransaction2);
|
|
}
|
|
|
|
const relatedTransaction3 = await Transactions.findOne({
|
|
offset: Math.floor(Math.random() * (await Transactions.count())),
|
|
});
|
|
const TransactionItem3 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (TransactionItem3?.setTransaction)
|
|
{
|
|
await
|
|
TransactionItem3.
|
|
setTransaction(relatedTransaction3);
|
|
}
|
|
|
|
const relatedTransaction4 = await Transactions.findOne({
|
|
offset: Math.floor(Math.random() * (await Transactions.count())),
|
|
});
|
|
const TransactionItem4 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4
|
|
});
|
|
if (TransactionItem4?.setTransaction)
|
|
{
|
|
await
|
|
TransactionItem4.
|
|
setTransaction(relatedTransaction4);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateTransactionItemWithProduct() {
|
|
|
|
const relatedProduct0 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const TransactionItem0 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (TransactionItem0?.setProduct)
|
|
{
|
|
await
|
|
TransactionItem0.
|
|
setProduct(relatedProduct0);
|
|
}
|
|
|
|
const relatedProduct1 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const TransactionItem1 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (TransactionItem1?.setProduct)
|
|
{
|
|
await
|
|
TransactionItem1.
|
|
setProduct(relatedProduct1);
|
|
}
|
|
|
|
const relatedProduct2 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const TransactionItem2 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (TransactionItem2?.setProduct)
|
|
{
|
|
await
|
|
TransactionItem2.
|
|
setProduct(relatedProduct2);
|
|
}
|
|
|
|
const relatedProduct3 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const TransactionItem3 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (TransactionItem3?.setProduct)
|
|
{
|
|
await
|
|
TransactionItem3.
|
|
setProduct(relatedProduct3);
|
|
}
|
|
|
|
const relatedProduct4 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const TransactionItem4 = await TransactionItems.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4
|
|
});
|
|
if (TransactionItem4?.setProduct)
|
|
{
|
|
await
|
|
TransactionItem4.
|
|
setProduct(relatedProduct4);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Shops.bulkCreate(ShopsData);
|
|
|
|
|
|
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
|
|
|
|
|
|
await Transactions.bulkCreate(TransactionsData);
|
|
|
|
|
|
|
|
|
|
await TransactionItems.bulkCreate(TransactionItemsData);
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateProductWithShop(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateTransactionWithShop(),
|
|
|
|
|
|
|
|
|
|
await associateTransactionWithCashier(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateTransactionItemWithTransaction(),
|
|
|
|
|
|
|
|
|
|
await associateTransactionItemWithProduct(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await queryInterface.bulkDelete('shops', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('transactions', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('transaction_items', null, {});
|
|
|
|
|
|
},
|
|
}; |