import { Controller, Get, Post, Patch, Delete, Param, Body, UsePipes, ValidationPipe, Query, ParseUUIDPipe, HttpCode, HttpStatus,} from '@nestjs/common'; import { FormService } from './form.service'; import { CreateFormDto } from './dto/create-form.dto'; import { UpdateFormDto } from './dto/update-form.dto'; import { Form } from './entity/form.entity'; @Controller('forms') export class FormController { constructor(private readonly formService: FormService) {} @Post() @UsePipes(new ValidationPipe({ transform: true, whitelist: true })) async create(@Body() body: CreateFormDto): Promise
{ return this.formService.create(body); } @Get('findAll') async findAll( @Query('page') page: string = '1', @Query('limit') limit: string = '10', ) { // The service returns the full pagination object return this.formService.findAll(parseInt(page, 10), parseInt(limit, 10)); } @Get(':id') async findOne( @Param('id', new ParseUUIDPipe()) id: string, ): Promise { return this.formService.findById(id); } @Patch(':id') @UsePipes(new ValidationPipe({ transform: true, whitelist: true })) async update( @Param('id', new ParseUUIDPipe()) id: string, @Body() body: UpdateFormDto, ): Promise { return this.formService.update(id, body); } @Delete(':id') @HttpCode(HttpStatus.NO_CONTENT) async remove(@Param('id', new ParseUUIDPipe()) id: string): Promise { return this.formService.remove(id); } }