import { Body, Controller, Get, Inject, Param, ParseIntPipe, Patch, Post, UseGuards, ValidationPipe } from '@nestjs/common'; import { ok } from '../common/api-response.js'; import type { JwtUser } from '../common/auth.types.js'; import { CurrentUser } from '../common/current-user.decorator.js'; import { JwtAuthGuard } from '../common/jwt-auth.guard.js'; import { RolesGuard } from '../common/roles.guard.js'; import { CreateKeyResultDto } from './dto/create-key-result.dto.js'; import { UpdateProgressDto } from './dto/update-progress.dto.js'; import { KeyResultsService } from './key-results.service.js'; @Controller('key-results') @UseGuards(JwtAuthGuard, RolesGuard) export class KeyResultsController { constructor(@Inject(KeyResultsService) private readonly keyResultsService: KeyResultsService) {} @Get(':id') async get(@Param('id', ParseIntPipe) id: number, @CurrentUser() user: JwtUser) { return ok(await this.keyResultsService.getById(id, user)); } @Post() async create( @Body(new ValidationPipe({ expectedType: CreateKeyResultDto, whitelist: true, forbidNonWhitelisted: true, transform: true })) dto: CreateKeyResultDto, @CurrentUser() user: JwtUser, ) { return ok(await this.keyResultsService.create(dto, user)); } @Patch(':id/progress') async updateProgress( @Param('id', ParseIntPipe) id: number, @Body(new ValidationPipe({ expectedType: UpdateProgressDto, whitelist: true, forbidNonWhitelisted: true, transform: true })) dto: UpdateProgressDto, @CurrentUser() user: JwtUser, ) { return ok(await this.keyResultsService.updateProgress(id, dto, user)); } }