From f70d1e506aa078a98c061385934827347c47cb34 Mon Sep 17 00:00:00 2001 From: Zhang Chengdong Date: Fri, 18 Sep 2026 12:43:00 +0000 Subject: [PATCH] chore(seed): seed deterministic points products Add five published points products, idempotent by English name, so the live mall has a redeemable catalog. Spendable demo points are credited by the API through the account ledger rather than here. --- scripts/seed-demo.mjs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/seed-demo.mjs b/scripts/seed-demo.mjs index 1630dee..f3764d1 100755 --- a/scripts/seed-demo.mjs +++ b/scripts/seed-demo.mjs @@ -342,6 +342,32 @@ for (const p of products) { } console.log(`products ready: ${products.length} across ${SHOPS.length} shops`); +// 6. points mall products (idempotent by English name). The demo customer's +// spendable points are credited by the API through the account ledger. +const POINTS_PRODUCTS = [ + { name: { en: "Insulated Mug", zh: "保温杯" }, image: "/mock/product-9.svg", points_price: 1200, stock: 300 }, + { name: { en: "Canvas Tote", zh: "帆布手提袋" }, image: "/mock/product-15.svg", points_price: 600, stock: 500 }, + { name: { en: "Phone Stand", zh: "手机支架" }, image: "/mock/product-7.svg", points_price: 400, stock: 800 }, + { name: { en: "Cable Organizer Set", zh: "数据线收纳套装" }, image: "/mock/product-3.svg", points_price: 300, stock: 1000 }, + { name: { en: "Notebook A5", zh: "A5 笔记本" }, image: "/mock/product-14.svg", points_price: 250, stock: 1200 }, +]; +{ + const listed = await call("GET", "/admin/points/products", { token: admin }); + if (listed.status !== 200) fail("list points products", listed); + const known = new Set(listed.data.map((p) => p.name.en)); + let created = 0; + for (const [index, product] of POINTS_PRODUCTS.entries()) { + if (known.has(product.name.en)) continue; + const res = await call("POST", "/admin/points/products", { + token: admin, + body: { ...product, position: index, published: true, recommend: index < 2 }, + }); + if (res.status !== 201) fail(`seed points product ${product.name.en}`, res); + created += 1; + } + console.log(`points products ready: ${POINTS_PRODUCTS.length} (${created} new)`); +} + console.log("\nDemo data seeded."); console.log(" platform admin : admin@vmall.local / admin1234 (apps/admin :3002)"); console.log(" shop owner : shop@vmall.local / shop12345 (apps/shop-admin :3001)");