From 524bb9dcf3bd1761b83c1b38238b97e6f4ef91c7 Mon Sep 17 00:00:00 2001 From: richarjiang Date: Wed, 23 Sep 2026 14:44:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(server):=20=E5=BC=80=E6=94=BE=E5=8F=AF?= =?UTF-8?q?=E9=A2=84=E7=BA=A6=E6=97=B6=E6=AE=B5=E5=88=97=E8=A1=A8=E4=B8=8E?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E7=BB=99=E6=9C=AA=E7=99=BB=E5=BD=95=E7=94=A8?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TimeSlotController 类级的 @UseGuards(JwtAuthGuard) 与服务层 getAvailableSlots / getSlotById 的可选 userId 契约不一致,导致游客访问预约课程列表会被 401 拒绝。去掉类级守卫、把两个 GET 端点的 userId 改为可选,未登录时返回 isBookedByMe=false 的公开时段列表,登录时保留个人预约标记。 /api/booking/my 等需要 userId 才能查的接口不受影响。 --- packages/server/src/time-slot/time-slot.controller.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/server/src/time-slot/time-slot.controller.ts b/packages/server/src/time-slot/time-slot.controller.ts index 2338ebb..da72f64 100644 --- a/packages/server/src/time-slot/time-slot.controller.ts +++ b/packages/server/src/time-slot/time-slot.controller.ts @@ -23,9 +23,14 @@ import { PublishDaySlotsDto } from './dto/publish-day-slots.dto' // --------------------------------------------------------------------------- // Member endpoints +// +// These endpoints are intentionally public — they power the "available +// courses" list and slot detail view that unauthenticated visitors can +// browse before deciding to log in. The service layer accepts an optional +// `userId`; when absent, it omits per-user booking flags +// (`isBookedByMe` / `myBookingId` / `myBookingStatus` are all false/null). // --------------------------------------------------------------------------- -@UseGuards(JwtAuthGuard) @Controller('time-slot') export class TimeSlotController { constructor(private readonly timeSlotService: TimeSlotService) {} @@ -33,7 +38,7 @@ export class TimeSlotController { @Get('available') getAvailableSlots( @Query() query: QuerySlotsDto, - @CurrentUser('sub') userId: string, + @CurrentUser('sub') userId?: string, ) { return this.timeSlotService.getAvailableSlots(query.date, userId) } @@ -41,7 +46,7 @@ export class TimeSlotController { @Get(':id') getSlotById( @Param('id') id: string, - @CurrentUser('sub') userId: string, + @CurrentUser('sub') userId?: string, ) { return this.timeSlotService.getSlotById(id, userId) }