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 =