import { Body, Controller, Get, Param, Put, UseGuards } from "@nestjs/common"; import { UpdateProgressDto, UpdateProgressSchema } from "@readabook/shared"; import { AuthGuard } from "../auth/auth.guard.js"; import { CurrentUser, CurrentUserParam } from "../auth/current-user.js"; import { ZodValidationPipe } from "../common/zod-validation.pipe.js"; import { ProgressService } from "./progress.service.js"; @Controller("progress") @UseGuards(AuthGuard) export class ProgressController { constructor(private readonly progress: ProgressService) {} @Get("continue") continue(@CurrentUserParam() user: CurrentUser) { return this.progress.continueReading(user.id); } @Get(":bookId") get(@CurrentUserParam() user: CurrentUser, @Param("bookId") bookId: string) { return this.progress.find(user.id, Number(bookId)); } @Put(":bookId") update( @CurrentUserParam() user: CurrentUser, @Param("bookId") bookId: string, @Body(new ZodValidationPipe(UpdateProgressSchema)) body: UpdateProgressDto ) { return this.progress.upsert(user.id, Number(bookId), body); } }