From 17bd700c2b28c0c9128735344bd3e3f3aa41bf08 Mon Sep 17 00:00:00 2001 From: que01 Date: Fri, 25 Sep 2026 08:36:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=AE=A9=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=B6=88=E8=B4=B9=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/prisma/seed.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts index 8d86828..2c44699 100644 --- a/apps/api/prisma/seed.ts +++ b/apps/api/prisma/seed.ts @@ -646,13 +646,36 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem }; async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTemplate): Promise { + const packageSample = getTemplateSampleContent(template.templateKey); + const sampleOfferings = packageSample?.offerings ?? []; + const offerings = template.offerings.map((item, index) => ({ + ...item, + ...(sampleOfferings[index] + ? { + name: sampleOfferings[index].name, + summary: sampleOfferings[index].summary, + config: { + ...item.config, + categoryKey: sampleOfferings[index].categoryKey, + }, + } + : {}), + })); + const trustContent = packageSample?.trustContent?.length + ? packageSample.trustContent.map((item, index) => ({ + ...template.trustContent[index], + type: item.type, + title: item.title, + content: item.content, + })) + : template.trustContent; await prisma.brandProfile.update({ where: { id: brandId }, data: { config: template.brandConfig, }, }); - for (const [sortOrder, item] of template.offerings.entries()) { + for (const [sortOrder, item] of offerings.entries()) { const offering = await prisma.offering.findUnique({ where: { brandId_name: { brandId, name: item.name } }, }); @@ -719,7 +742,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla }, }); } - for (const [sortOrder, item] of template.trustContent.entries()) { + for (const [sortOrder, item] of trustContent.entries()) { const existing = await prisma.trustContent.findFirst({ where: { brandId, type: item.type, title: item.title }, }); @@ -731,7 +754,6 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla where: { brandId, targetType: "brand" }, orderBy: { createdAt: "asc" }, }); - const packageSample = getTemplateSampleContent(template.templateKey); const formData = { name: template.inquiryForm.name, purpose: "inquiry",