From 3fa104ca61565f0b14c040906769176c0b174750 Mon Sep 17 00:00:00 2001 From: Zhang Chengdong Date: Fri, 18 Sep 2026 13:22:47 +0000 Subject: [PATCH] chore(seed): seed an active group-buying activity Add one active activity for the demo shop on a SKU that is not already in the seeded flash sale, idempotent by name, so the live mall can open and join a group. --- scripts/seed-demo.mjs | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/scripts/seed-demo.mjs b/scripts/seed-demo.mjs index f5ec91e..882d98f 100755 --- a/scripts/seed-demo.mjs +++ b/scripts/seed-demo.mjs @@ -409,6 +409,50 @@ const POINTS_PRODUCTS = [ console.log("flash sale ready"); } +// 8. an active group-buying activity for the demo shop (idempotent by name). +{ + const owner = ownerTokens.get("demo-store"); + const listed = await call("GET", "/shop/group-buying-activities", { token: owner }); + if (listed.status !== 200) fail("list group activities", listed); + const known = new Set(listed.data.map((a) => a.name.en)); + if (!known.has("Weekend group deal")) { + const products = await call("GET", "/shop/products?per_page=100", { token: owner }); + if (products.status !== 200) fail("list shop products", products); + const flash = await call("GET", "/shop/flash-sales", { token: owner }); + const flashSkus = new Set( + (flash.data ?? []).flatMap((s) => s.items ?? []).map((i) => i.sku_id), + ); + const used = new Set(listed.data.map((a) => a.sku_id)); + // A SKU already in an overlapping flash sale cannot join a group activity. + const sku = (products.data.items ?? []) + .flatMap((p) => p.skus ?? []) + .find((s) => s.active && s.stock > 0 && !flashSkus.has(s.id) && !used.has(s.id)); + if (!sku) fail("find a group-buying SKU", { status: 0, data: "no free SKU" }); + + const now = Date.now(); + const res = await call("POST", "/shop/group-buying-activities", { + token: owner, + body: { + sku_id: sku.id, + name: { en: "Weekend group deal", zh: "周末拼团" }, + description: { + en: "Gather two friends to unlock the group price.", + zh: "两人成团,享拼团价。", + }, + group_price_minor: Math.max(1, Math.round(sku.price_minor * 0.75)), + currency: sku.currency, + required_members: 2, + starts_at: new Date(now - 3600 * 1000).toISOString(), + ends_at: new Date(now + 7 * 24 * 3600 * 1000).toISOString(), + group_lifetime_hours: 24, + enabled: true, + }, + }); + if (res.status !== 201) fail("seed group activity", res); + } + console.log("group buying ready"); +} + 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)");