diff --git a/apps/api/src/admin-workspace.controller.ts b/apps/api/src/admin-workspace.controller.ts index 64409ba..9f036e3 100644 --- a/apps/api/src/admin-workspace.controller.ts +++ b/apps/api/src/admin-workspace.controller.ts @@ -43,9 +43,9 @@ class AdminWorkspaceController { @Get("offerings") async listOfferings(@Req() request: FastifyRequest): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; const items = await this.prisma.offering.findMany({ - where: { brandId: this.brandId() }, + where: { brandId }, orderBy: { sortOrder: "asc" }, }); return items.map((item) => { @@ -64,7 +64,7 @@ class AdminWorkspaceController { @Req() request: FastifyRequest, @Body() body: CreateOfferingDto, ): Promise { - this.requireAdmin(request); + const brandId = this.requireAdmin(request).brandId; const { config, sections, media, cta, ...fields } = body; const configValue = { ...(config ?? {}), @@ -77,7 +77,7 @@ class AdminWorkspaceController { return this.prisma.offering.create({ data: { ...fields, - brandId: this.brandId(), + brandId, config: configValue as Prisma.InputJsonValue, }, }); @@ -89,8 +89,8 @@ class AdminWorkspaceController { @Param("id") id: string, @Body() body: UpdateOfferingDto, ): Promise { - this.requireAdmin(request); - const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } }); + const brandId = this.requireAdmin(request).brandId; + const item = await this.prisma.offering.findFirst({ where: { id, brandId } }); if (!item) throw new BadRequestException("业务提供项不存在"); const { config, sections, media, cta, ...fields } = body; const configValue = { @@ -119,8 +119,8 @@ class AdminWorkspaceController { @Delete("offerings/:id") async deleteOffering(@Req() request: FastifyRequest, @Param("id") id: string): Promise { - this.requireAdmin(request); - const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } }); + const brandId = this.requireAdmin(request).brandId; + const item = await this.prisma.offering.findFirst({ where: { id, brandId } }); if (!item) throw new BadRequestException("业务提供项不存在"); const [forms, bookings, items] = await Promise.all([ this.prisma.inquiryForm.count({ where: { offeringId: id } }), @@ -336,19 +336,19 @@ class AdminWorkspaceController { @Get("template/preview") async previewTemplate(@Req() request: FastifyRequest): Promise { this.requireAdmin(request); - return this.templateWorkspace.preview(this.brandId()); + return this.templateWorkspace.preview(this.requireAdmin(request).brandId); } @Post("template/upgrade") async upgradeTemplate(@Req() request: FastifyRequest): Promise { this.requireAdmin(request); - return this.templateWorkspace.upgrade(this.brandId()); + return this.templateWorkspace.upgrade(this.requireAdmin(request).brandId); } @Post("template/rollback") async rollbackTemplate(@Req() request: FastifyRequest): Promise { this.requireAdmin(request); - return this.templateWorkspace.rollback(this.brandId()); + return this.templateWorkspace.rollback(this.requireAdmin(request).brandId); } @Patch("modules/:id")