105 lines
2.6 KiB
TypeScript
105 lines
2.6 KiB
TypeScript
import nextEnv from "@next/env";
|
|
import { getPool } from "../src/server/db/pool";
|
|
import {
|
|
createCategory,
|
|
createInventoryItem,
|
|
createProduct,
|
|
createShop,
|
|
createTable,
|
|
listInventory,
|
|
listCategories,
|
|
listProducts,
|
|
listShops,
|
|
listTables
|
|
} from "../src/server/db/queries";
|
|
import { seedParityData } from "../src/server/services/parity";
|
|
|
|
nextEnv.loadEnvConfig(process.cwd());
|
|
|
|
const shops = await listShops();
|
|
const shop =
|
|
shops[0] ??
|
|
(await createShop({
|
|
name: "GoodGo Cafe MVP",
|
|
vertical: "cafe",
|
|
phone: "0900000000",
|
|
email: "ops@goodgo.vn",
|
|
description: "MVP shop created from Next.js seed",
|
|
statusId: 2
|
|
}));
|
|
|
|
let categories = await listCategories(shop.id);
|
|
if (categories.length === 0) {
|
|
categories = [
|
|
await createCategory({ shopId: shop.id, name: "Coffee", displayOrder: 1 }),
|
|
await createCategory({ shopId: shop.id, name: "Tea", displayOrder: 2 }),
|
|
await createCategory({ shopId: shop.id, name: "Food", displayOrder: 3 })
|
|
];
|
|
}
|
|
|
|
const products = await listProducts(shop.id);
|
|
if (products.length === 0) {
|
|
await createProduct({
|
|
shopId: shop.id,
|
|
name: "Americano",
|
|
price: 45000,
|
|
vertical: shop.vertical,
|
|
categoryId: categories[0]?.id,
|
|
sku: "CF-AMERICANO",
|
|
initialQuantity: 40
|
|
});
|
|
await createProduct({
|
|
shopId: shop.id,
|
|
name: "Latte",
|
|
price: 59000,
|
|
vertical: shop.vertical,
|
|
categoryId: categories[0]?.id,
|
|
sku: "CF-LATTE",
|
|
initialQuantity: 35
|
|
});
|
|
await createProduct({
|
|
shopId: shop.id,
|
|
name: "Peach Tea",
|
|
price: 52000,
|
|
vertical: shop.vertical,
|
|
categoryId: categories[1]?.id,
|
|
sku: "TEA-PEACH",
|
|
initialQuantity: 28
|
|
});
|
|
await createProduct({
|
|
shopId: shop.id,
|
|
name: "Croissant",
|
|
price: 39000,
|
|
vertical: shop.vertical,
|
|
categoryId: categories[2]?.id,
|
|
sku: "FD-CROISSANT",
|
|
initialQuantity: 16
|
|
});
|
|
}
|
|
|
|
const tables = await listTables(shop.id);
|
|
if (tables.length === 0) {
|
|
await createTable({ shopId: shop.id, tableNumber: "A1", capacity: 2, zone: "Front" });
|
|
await createTable({ shopId: shop.id, tableNumber: "A2", capacity: 4, zone: "Front" });
|
|
await createTable({ shopId: shop.id, tableNumber: "B1", capacity: 6, zone: "Garden" });
|
|
}
|
|
|
|
const inventory = await listInventory(shop.id);
|
|
if (!inventory.some((item) => item.name === "Arabica beans")) {
|
|
await createInventoryItem({
|
|
shopId: shop.id,
|
|
name: "Arabica beans",
|
|
itemTypeId: 1,
|
|
unit: "kg",
|
|
costPerUnit: 240000,
|
|
quantity: 8,
|
|
reorderLevel: 5,
|
|
supplierName: "GoodGo Supply"
|
|
});
|
|
}
|
|
|
|
console.log(`Seed completed for shop: ${shop.name}`);
|
|
await seedParityData(shop.id);
|
|
console.log("Full TPOS parity seed completed");
|
|
await getPool().end();
|