From 9ef91194df14a1d086763ed6c2035df72e760a69 Mon Sep 17 00:00:00 2001 From: que01 Date: Wed, 23 Sep 2026 02:19:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E6=88=90=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E5=8C=BA=E6=8E=A5=E5=8F=A3=E5=93=81=E7=89=8C=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/admin-workspace.controller.ts | 39 +++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/apps/api/src/admin-workspace.controller.ts b/apps/api/src/admin-workspace.controller.ts index 9f036e3..2731e32 100644 --- a/apps/api/src/admin-workspace.controller.ts +++ b/apps/api/src/admin-workspace.controller.ts @@ -150,8 +150,7 @@ class AdminWorkspaceController { } @Get() async get(@Req() request: FastifyRequest): Promise { - this.requireAdmin(request); - const brandId = this.brandId(); + const brandId = this.requireAdmin(request).brandId; const [brand, installations, modules, fields, offerings, forms] = await Promise.all([ this.prisma.brandProfile.findUnique({ where: { id: brandId } }), this.prisma.brandTemplateInstallation.findMany({ where: { brandId } }), @@ -357,9 +356,9 @@ class AdminWorkspaceController { @Param("id") id: string, @Body() body: UpdateModuleDto, ): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; const item = await this.prisma.brandModule.findFirst({ - where: { id, brandId: this.brandId() }, + where: { id, brandId }, }); if (!item) throw new BadRequestException("品牌模块不存在"); const { config, ...fields } = body; @@ -377,11 +376,11 @@ class AdminWorkspaceController { @Req() request: FastifyRequest, @Body() body: CreateFieldDefinitionDto, ): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; return this.prisma.brandFieldDefinition.create({ data: { ...body, - brandId: this.brandId(), + brandId, source: "custom", options: body.options as Prisma.InputJsonValue, visibleWhen: body.visibleWhen as Prisma.InputJsonValue, @@ -395,9 +394,9 @@ class AdminWorkspaceController { @Param("id") id: string, @Body() body: UpdateFieldDefinitionDto, ): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; const item = await this.prisma.brandFieldDefinition.findFirst({ - where: { id, brandId: this.brandId() }, + where: { id, brandId }, }); if (!item) throw new BadRequestException("品牌字段不存在"); const { options, visibleWhen, ...fields } = body; @@ -413,9 +412,9 @@ class AdminWorkspaceController { @Delete("fields/:id") async deleteField(@Req() request: FastifyRequest, @Param("id") id: string): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; const item = await this.prisma.brandFieldDefinition.findFirst({ - where: { id, brandId: this.brandId(), source: "custom" }, + where: { id, brandId, source: "custom" }, }); if (!item) throw new BadRequestException("自定义字段不存在或不可删除"); await this.prisma.brandFieldDefinition.delete({ where: { id } }); @@ -424,18 +423,18 @@ class AdminWorkspaceController { @Get("forms") listForms(@Req() request: FastifyRequest): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; return this.prisma.inquiryForm.findMany({ - where: { brandId: this.brandId() }, + where: { brandId }, orderBy: { updatedAt: "desc" }, }); } @Get("submissions") listSubmissions(@Req() request: FastifyRequest): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; return this.prisma.inquirySubmission.findMany({ - where: { brandId: this.brandId() }, + where: { brandId }, include: { inquiryForm: { select: { name: true } }, offering: { select: { id: true, name: true } }, @@ -450,9 +449,9 @@ class AdminWorkspaceController { @Param("id") id: string, @Body() body: UpdateInquirySubmissionDto, ): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; const item = await this.prisma.inquirySubmission.findFirst({ - where: { id, brandId: this.brandId() }, + where: { id, brandId }, }); if (!item) throw new BadRequestException("咨询记录不存在"); return this.prisma.$transaction(async (tx) => { @@ -479,13 +478,13 @@ class AdminWorkspaceController { @Post("forms") createForm(@Req() request: FastifyRequest, @Body() body: CreateInquiryFormDto): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; if (validateFieldSnapshot(body.fieldsSnapshot).length) throw new BadRequestException("咨询表单字段定义无效"); return this.prisma.inquiryForm.create({ data: { ...body, - brandId: this.brandId(), + brandId, version: 1, fieldsSnapshot: body.fieldsSnapshot as Prisma.InputJsonValue, }, @@ -498,9 +497,9 @@ class AdminWorkspaceController { @Param("id") id: string, @Body() body: UpdateInquiryFormDto, ): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; const item = await this.prisma.inquiryForm.findFirst({ - where: { id, brandId: this.brandId() }, + where: { id, brandId }, }); if (!item) throw new BadRequestException("咨询表单不存在"); const { fieldsSnapshot, ...fields } = body;