331 lines
6.4 KiB
JavaScript
331 lines
6.4 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Invoices = db.invoices;
|
|
|
|
const Orders = db.orders;
|
|
|
|
const Products = db.products;
|
|
|
|
const InvoicesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_amount: 150,
|
|
|
|
invoice_date: new Date('2023-10-06T15:00:00Z'),
|
|
|
|
paid: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_amount: 300,
|
|
|
|
invoice_date: new Date('2023-10-07T16:00:00Z'),
|
|
|
|
paid: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_amount: 450,
|
|
|
|
invoice_date: new Date('2023-10-08T17:00:00Z'),
|
|
|
|
paid: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_amount: 200,
|
|
|
|
invoice_date: new Date('2023-10-09T18:00:00Z'),
|
|
|
|
paid: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
total_amount: 350,
|
|
|
|
invoice_date: new Date('2023-10-10T19:00:00Z'),
|
|
|
|
paid: false,
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_type: 'dtf_print',
|
|
|
|
description: 'Custom logo embroidery on 50 shirts',
|
|
|
|
order_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
status: 'pending',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_type: 'embroidery',
|
|
|
|
description: 'DTF print on 100 tote bags',
|
|
|
|
order_date: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
status: 'completed',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_type: 'dtf_print',
|
|
|
|
description: 'Name embroidery on 30 caps',
|
|
|
|
order_date: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
status: 'pending',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_type: 'dtf_print',
|
|
|
|
description: 'DTF print on 200 t-shirts',
|
|
|
|
order_date: new Date('2023-10-04T13:00:00Z'),
|
|
|
|
status: 'in_progress',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
order_type: 'dtf_print',
|
|
|
|
description: 'Custom patch embroidery on 10 jackets',
|
|
|
|
order_date: new Date('2023-10-05T14:00:00Z'),
|
|
|
|
status: 'in_progress',
|
|
},
|
|
];
|
|
|
|
const ProductsData = [
|
|
{
|
|
name: 'Tote Bag',
|
|
|
|
price: 5.99,
|
|
|
|
stock_quantity: 150,
|
|
|
|
// type code here for "images" field
|
|
},
|
|
|
|
{
|
|
name: 'T-Shirt',
|
|
|
|
price: 9.99,
|
|
|
|
stock_quantity: 200,
|
|
|
|
// type code here for "images" field
|
|
},
|
|
|
|
{
|
|
name: 'Cap',
|
|
|
|
price: 4.99,
|
|
|
|
stock_quantity: 100,
|
|
|
|
// type code here for "images" field
|
|
},
|
|
|
|
{
|
|
name: 'Jacket',
|
|
|
|
price: 19.99,
|
|
|
|
stock_quantity: 50,
|
|
|
|
// type code here for "images" field
|
|
},
|
|
|
|
{
|
|
name: 'Shirt',
|
|
|
|
price: 14.99,
|
|
|
|
stock_quantity: 75,
|
|
|
|
// type code here for "images" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateInvoiceWithClient() {
|
|
const relatedClient0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Invoice0 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Invoice0?.setClient) {
|
|
await Invoice0.setClient(relatedClient0);
|
|
}
|
|
|
|
const relatedClient1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Invoice1 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Invoice1?.setClient) {
|
|
await Invoice1.setClient(relatedClient1);
|
|
}
|
|
|
|
const relatedClient2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Invoice2 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Invoice2?.setClient) {
|
|
await Invoice2.setClient(relatedClient2);
|
|
}
|
|
|
|
const relatedClient3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Invoice3 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Invoice3?.setClient) {
|
|
await Invoice3.setClient(relatedClient3);
|
|
}
|
|
|
|
const relatedClient4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Invoice4 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Invoice4?.setClient) {
|
|
await Invoice4.setClient(relatedClient4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateOrderWithClient() {
|
|
const relatedClient0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setClient) {
|
|
await Order0.setClient(relatedClient0);
|
|
}
|
|
|
|
const relatedClient1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setClient) {
|
|
await Order1.setClient(relatedClient1);
|
|
}
|
|
|
|
const relatedClient2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setClient) {
|
|
await Order2.setClient(relatedClient2);
|
|
}
|
|
|
|
const relatedClient3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order3 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Order3?.setClient) {
|
|
await Order3.setClient(relatedClient3);
|
|
}
|
|
|
|
const relatedClient4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order4 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Order4?.setClient) {
|
|
await Order4.setClient(relatedClient4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Invoices.bulkCreate(InvoicesData);
|
|
|
|
await Orders.bulkCreate(OrdersData);
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateInvoiceWithClient(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateOrderWithClient(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('invoices', null, {});
|
|
|
|
await queryInterface.bulkDelete('orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
},
|
|
};
|