From cbe9d26288c115a61584a264d83be443f0eaf8a6 Mon Sep 17 00:00:00 2001 From: que01 Date: Wed, 23 Sep 2026 12:05:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=BA=E5=AE=9A=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=93=81=E7=89=8C=E8=A7=A3=E6=9E=90=E9=81=BF=E5=85=8D=E5=A4=9A?= =?UTF-8?q?=E5=93=81=E7=89=8C=E4=B8=B2=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/prisma/seed.ts | 48 +++++++++++++++++++ apps/api/src/main.ts | 5 +- .../src/modules/session/session.controller.ts | 5 +- apps/api/test/http.integration.test.js | 2 + 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts index ac31059..fe30886 100644 --- a/apps/api/prisma/seed.ts +++ b/apps/api/prisma/seed.ts @@ -74,6 +74,54 @@ async function main(): Promise { update: { isEnabled: true, role: "owner" }, create: { adminUserId: admin.id, brandId: brand.id, role: "owner" }, }); + + const doorsBrand = await prisma.brandProfile.upsert({ + where: { id: "00000000-0000-0000-0000-000000000002" }, + update: {}, + create: { + id: "00000000-0000-0000-0000-000000000002", + slug: "linjing-doors", + name: "林境门作", + templateKey: "doors", + tagline: "为别墅空间定制有秩序感的门系统", + description: "从入户大门到室内户内门,提供完整的门系统设计与落地服务。", + hours: "周一至周六 09:00-18:00", + address: "城市设计中心 3F", + contactPhone: "13800000000", + contactWechat: "linjing-doors", + }, + }); + for (const offering of [ + { + name: "别墅入户大门", + description: "结合建筑立面与入户动线定制门体、五金和安装方案。", + priceText: "预约沟通", + sortOrder: 1, + }, + { + name: "院门与围合系统", + description: "院门、围墙和庭院动线的一体化设计与施工配合。", + priceText: "预约沟通", + sortOrder: 2, + }, + { + name: "室内户内门系统", + description: "根据空间风格定制户内门、隐形门和装饰门。", + priceText: "预约沟通", + sortOrder: 3, + }, + ]) { + await prisma.offering.upsert({ + where: { brandId_name: { brandId: doorsBrand.id, name: offering.name } }, + update: offering, + create: { ...offering, brandId: doorsBrand.id, kind: "service" }, + }); + } + await prisma.brandMembership.upsert({ + where: { adminUserId_brandId: { adminUserId: admin.id, brandId: doorsBrand.id } }, + update: { isEnabled: true, role: "owner" }, + create: { adminUserId: admin.id, brandId: doorsBrand.id, role: "owner" }, + }); } main().finally(() => prisma.$disconnect()); diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index e39dd53..6a45059 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -69,7 +69,10 @@ export class PublicController { @Get("brand") async brand(): Promise { - return this.prisma.brandProfile.findFirst({ + return this.prisma.brandProfile.findUnique({ + where: { + id: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001", + }, select: { id: true, name: true, diff --git a/apps/api/src/modules/session/session.controller.ts b/apps/api/src/modules/session/session.controller.ts index 639ddfa..2d70a74 100644 --- a/apps/api/src/modules/session/session.controller.ts +++ b/apps/api/src/modules/session/session.controller.ts @@ -15,7 +15,10 @@ export class CustomerSessionController { @Post("wechat") async wechatLogin(@Body() body: WechatLoginDto): Promise<{ token: string }> { const session = await this.wechatAuth.exchangeCode(body.code); - const brand = await this.prisma.brandProfile.findFirst({ select: { id: true } }); + const brand = await this.prisma.brandProfile.findUnique({ + where: { id: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001" }, + select: { id: true }, + }); if (!brand) throw new BadRequestException("品牌尚未初始化"); await this.prisma.customerUser.upsert({ where: { brandId_openid: { brandId: brand.id, openid: session.openid } }, diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index abab12e..21ee97a 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -781,6 +781,8 @@ test("admin can list and switch only enabled brand memberships", async () => { assert.equal(brands.statusCode, 200); const memberships = JSON.parse(brands.body); assert.ok(memberships.some((item) => item.brand.id === brandId)); + assert.ok(memberships.some((item) => item.brand.slug === "linjing-doors")); + assert.ok(memberships.length >= 2); const denied = await request("/admin/brands/00000000-0000-0000-0000-000000000000/switch", { method: "POST", headers: { authorization: `Bearer ${token}` },