From 6835a2b0fdcc44a54b821de1b0beb043b3b0c07a Mon Sep 17 00:00:00 2001 From: que01 Date: Wed, 23 Sep 2026 02:21:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8E=A5=E5=85=A5=E5=93=81?= =?UTF-8?q?=E7=89=8C=E9=85=8D=E7=BD=AE=E7=AE=A1=E7=90=86=E5=91=98=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/main.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index bcbfabe..4bf4c8c 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -686,8 +686,13 @@ export class AdminBookingController { @Controller("admin/config") export class AdminConfigController { constructor(private readonly prisma: PrismaService) {} - private brandId(): string { - return process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001"; + private brandId(request?: FastifyRequest): string { + if (!request) return process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001"; + const token = request.headers.authorization?.replace(/^Bearer\s+/i, ""); + if (!token) throw new UnauthorizedException("缺少管理员登录态"); + const identity = readIdentity(token); + if (identity.role !== "admin") throw new ForbiddenException("无管理员权限"); + return identity.brandId; } private requireAdmin(request: FastifyRequest): void { const token = request.headers.authorization?.replace(/^Bearer\s+/i, ""); @@ -703,7 +708,7 @@ export class AdminConfigController { @Get("brand") getBrand(@Req() request: FastifyRequest): Promise { this.requireAdmin(request); - return this.prisma.brandProfile.findUnique({ where: { id: this.brandId() } }); + return this.prisma.brandProfile.findUnique({ where: { id: this.brandId(request) } }); } @Patch("brand") async updateBrand( @@ -713,7 +718,7 @@ export class AdminConfigController { this.requireAdmin(request); const { config, ...fields } = body; const current = await this.prisma.brandProfile.findUnique({ - where: { id: this.brandId() }, + where: { id: this.brandId(request) }, select: { config: true }, }); const currentConfig =