411 lines
7.5 KiB
JavaScript
411 lines
7.5 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Configurations = db.configurations;
|
|
|
|
const Orders = db.orders;
|
|
|
|
const PaymentMethods = db.payment_methods;
|
|
|
|
const Products = db.products;
|
|
|
|
const Reports = db.reports;
|
|
|
|
const Shippers = db.shippers;
|
|
|
|
const ConfigurationsData = [
|
|
{
|
|
order_number_format: '25-XXX',
|
|
|
|
custom_start: 3001,
|
|
},
|
|
|
|
{
|
|
order_number_format: 'Joseph J. Thomson',
|
|
|
|
custom_start: 3,
|
|
},
|
|
|
|
{
|
|
order_number_format: 'Frederick Gowland Hopkins',
|
|
|
|
custom_start: 8,
|
|
},
|
|
|
|
{
|
|
order_number_format: 'Emil Fischer',
|
|
|
|
custom_start: 7,
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
order_number: '#25-1001',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'OrderwithIssue',
|
|
|
|
order_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
buyer_details: 'John Doe, 123 Main St, City',
|
|
|
|
shipping_details: 'FedEx, 456 Elm St, City',
|
|
|
|
issue_notes: 'None',
|
|
},
|
|
|
|
{
|
|
order_number: '#25-1002',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'OrderDelivered',
|
|
|
|
order_date: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
buyer_details: 'Jane Smith, 789 Oak St, City',
|
|
|
|
shipping_details: 'UPS, 101 Pine St, City',
|
|
|
|
issue_notes: 'Check address',
|
|
},
|
|
|
|
{
|
|
order_number: '#25-1003',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'OrderDelivered',
|
|
|
|
order_date: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
buyer_details: 'Michael Brown, 234 Maple St, City',
|
|
|
|
shipping_details: 'DHL, 567 Birch St, City',
|
|
|
|
issue_notes: 'None',
|
|
},
|
|
|
|
{
|
|
order_number: '#25-1004',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'OrderShipped',
|
|
|
|
order_date: new Date('2023-10-04T13:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
buyer_details: 'Emily Jones, 890 Cedar St, City',
|
|
|
|
shipping_details: 'USPS, 678 Spruce St, City',
|
|
|
|
issue_notes: 'None',
|
|
},
|
|
];
|
|
|
|
const PaymentMethodsData = [
|
|
{
|
|
method_name: 'Credit Card',
|
|
},
|
|
|
|
{
|
|
method_name: 'PayPal',
|
|
},
|
|
|
|
{
|
|
method_name: 'Bank Transfer',
|
|
},
|
|
|
|
{
|
|
method_name: 'Cash on Delivery',
|
|
},
|
|
];
|
|
|
|
const ProductsData = [
|
|
{
|
|
name: 'Product A',
|
|
|
|
brand: 'Brand X',
|
|
|
|
type: 'SoftGels',
|
|
|
|
stock: 100,
|
|
|
|
sold_today: 5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Product B',
|
|
|
|
brand: 'Brand Y',
|
|
|
|
type: 'SoftGels',
|
|
|
|
stock: 200,
|
|
|
|
sold_today: 10,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Product C',
|
|
|
|
brand: 'Brand Z',
|
|
|
|
type: 'Capsulas',
|
|
|
|
stock: 150,
|
|
|
|
sold_today: 7,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Product D',
|
|
|
|
brand: 'Brand X',
|
|
|
|
type: 'Capsulas',
|
|
|
|
stock: 80,
|
|
|
|
sold_today: 3,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ReportsData = [
|
|
{
|
|
report_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
users_per_day: 50,
|
|
|
|
revenue: 10000,
|
|
|
|
quantity_by_shipper: 20,
|
|
|
|
order_status_breakdown: 'Received: 10, Reviewed: 5, Packed: 3, Shipped: 2',
|
|
|
|
shipper_performance: 'FedEx: 5, UPS: 3, DHL: 2',
|
|
},
|
|
|
|
{
|
|
report_date: new Date('2023-10-02T00:00:00Z'),
|
|
|
|
users_per_day: 60,
|
|
|
|
revenue: 12000,
|
|
|
|
quantity_by_shipper: 25,
|
|
|
|
order_status_breakdown: 'Received: 12, Reviewed: 6, Packed: 4, Shipped: 3',
|
|
|
|
shipper_performance: 'FedEx: 6, UPS: 4, DHL: 3',
|
|
},
|
|
|
|
{
|
|
report_date: new Date('2023-10-03T00:00:00Z'),
|
|
|
|
users_per_day: 55,
|
|
|
|
revenue: 11000,
|
|
|
|
quantity_by_shipper: 22,
|
|
|
|
order_status_breakdown: 'Received: 11, Reviewed: 5, Packed: 3, Shipped: 3',
|
|
|
|
shipper_performance: 'FedEx: 5, UPS: 4, DHL: 3',
|
|
},
|
|
|
|
{
|
|
report_date: new Date('2023-10-04T00:00:00Z'),
|
|
|
|
users_per_day: 65,
|
|
|
|
revenue: 13000,
|
|
|
|
quantity_by_shipper: 30,
|
|
|
|
order_status_breakdown: 'Received: 15, Reviewed: 7, Packed: 5, Shipped: 3',
|
|
|
|
shipper_performance: 'FedEx: 7, UPS: 5, DHL: 3',
|
|
},
|
|
];
|
|
|
|
const ShippersData = [
|
|
{
|
|
name: 'FedEx',
|
|
|
|
contact_info: '123 FedEx St, City, 555-1234',
|
|
},
|
|
|
|
{
|
|
name: 'UPS',
|
|
|
|
contact_info: '456 UPS Ave, City, 555-5678',
|
|
},
|
|
|
|
{
|
|
name: 'DHL',
|
|
|
|
contact_info: '789 DHL Blvd, City, 555-9012',
|
|
},
|
|
|
|
{
|
|
name: 'USPS',
|
|
|
|
contact_info: '101 USPS Rd, City, 555-3456',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateOrderWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setUser) {
|
|
await Order0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setUser) {
|
|
await Order1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setUser) {
|
|
await Order2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order3 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Order3?.setUser) {
|
|
await Order3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateProductWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setUser) {
|
|
await Product0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setUser) {
|
|
await Product1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setUser) {
|
|
await Product2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Product3 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Product3?.setUser) {
|
|
await Product3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Configurations.bulkCreate(ConfigurationsData);
|
|
|
|
await Orders.bulkCreate(OrdersData);
|
|
|
|
await PaymentMethods.bulkCreate(PaymentMethodsData);
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
await Reports.bulkCreate(ReportsData);
|
|
|
|
await Shippers.bulkCreate(ShippersData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateOrderWithUser(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateProductWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('configurations', null, {});
|
|
|
|
await queryInterface.bulkDelete('orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('payment_methods', null, {});
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
|
|
await queryInterface.bulkDelete('reports', null, {});
|
|
|
|
await queryInterface.bulkDelete('shippers', null, {});
|
|
},
|
|
};
|