From 4470302b3f0ac72dd0c8337caf82ffa10bba2b86 Mon Sep 17 00:00:00 2001 From: que01 Date: Sun, 20 Sep 2026 09:54:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B6=E5=8F=A3=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=BB=E6=A8=A1=E6=9D=BF=E7=AD=96=E7=95=A5=E4=B8=8E=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E9=A1=B9=E5=93=8D=E5=BA=94=E5=A5=91=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/main.ts | 23 +++++++++++++++++------ apps/api/test/http.integration.test.js | 6 ++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 93d0ebd..732a301 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -184,12 +184,21 @@ export class AdminWorkspaceController { } @Get("offerings") - listOfferings(@Req() request: FastifyRequest): Promise { + async listOfferings(@Req() request: FastifyRequest): Promise { this.requireAdmin(request); - return this.prisma.offering.findMany({ + const items = await this.prisma.offering.findMany({ where: { brandId: this.brandId() }, orderBy: { sortOrder: "asc" }, }); + return items.map((item) => { + const config = (item.config ?? {}) as Record; + return { + ...item, + sections: config.sections ?? [], + media: config.media ?? [], + cta: config.cta ?? null, + }; + }); } @Post("offerings") @@ -279,10 +288,12 @@ export class AdminWorkspaceController { this.requireAdmin(request); const brandId = this.brandId(); const template = brandTemplates[body.templateKey]; - const existing = await this.prisma.brandTemplateInstallation.findUnique({ - where: { brandId_templateKey: { brandId, templateKey: body.templateKey } }, - }); - if (existing) throw new BadRequestException("该模板已经安装"); + const existing = await this.prisma.brandTemplateInstallation.findFirst({ where: { brandId } }); + if (existing) { + if (existing.templateKey === body.templateKey) + throw new BadRequestException("该模板已经安装"); + throw new BadRequestException("品牌已经安装主模板,请先完成模板切换流程"); + } const modules = [ ["text", "品牌介绍"], ["trust-content", "信任证明"], diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index e8bff65..bc23509 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -71,6 +71,12 @@ test("admin can install a template and public workspace exposes enabled configur const publicWorkspace = await request("/public/workspace"); assert.equal(publicWorkspace.statusCode, 200); assert.equal(JSON.parse(publicWorkspace.body).modules.length, 4); + const conflict = await request("/admin/workspace/install", { + method: "POST", + headers: { authorization: `Bearer ${token}` }, + payload: { templateKey: "food" }, + }); + assert.equal(conflict.statusCode, 400); } finally { await prisma.brandFieldDefinition.deleteMany({ where: { brandId } }); await prisma.brandModule.deleteMany({ where: { brandId } });