Loading backend/src/town/town.controller.ts +14 −23 Original line number Diff line number Diff line import { Controller, Get, Post, Body, Patch, Param, Delete, } from '@nestjs/common'; import { Controller, Get, Post, Param, Delete, UseInterceptors, UploadedFile, Body } from '@nestjs/common'; import { TownService } from './town.service'; import { ApiTags } from '@nestjs/swagger'; import { FileValidationPipe } from 'src/shared/pipe/file-validation.pipe'; import { fileInterceptor } from 'src/shared/interceptors/file-save.interceptor'; import { CreateTownDto } from './dto/create-town.dto'; import { UpdateTownDto } from './dto/update-town.dto'; @Controller('town') @ApiTags('Agregar un pueblo') export class TownController { constructor(private readonly townService: TownService) {} @Post() create(@Body() createTownDto: CreateTownDto) { return this.townService.create(createTownDto); @UseInterceptors(fileInterceptor('image', 'static/towns/', ['.jpg', '.jpeg', '.png'])) async create(@UploadedFile(new FileValidationPipe()) file, @Body() createTownDto: CreateTownDto) { try { createTownDto.imageName = file.filename; await this.townService.create(createTownDto); return { message: 'Town created successfully' }; } catch (error) { throw error; } } @Get() Loading @@ -25,16 +26,6 @@ export class TownController { return this.townService.findAll(); } @Get(':id') findOne(@Param('id') id: string) { return this.townService.findOne(+id); } @Patch(':id') update(@Param('id') id: string, @Body() updateTownDto: UpdateTownDto) { return this.townService.update(+id, updateTownDto); } @Delete(':id') remove(@Param('id') id: string) { return this.townService.remove(+id); Loading Loading
backend/src/town/town.controller.ts +14 −23 Original line number Diff line number Diff line import { Controller, Get, Post, Body, Patch, Param, Delete, } from '@nestjs/common'; import { Controller, Get, Post, Param, Delete, UseInterceptors, UploadedFile, Body } from '@nestjs/common'; import { TownService } from './town.service'; import { ApiTags } from '@nestjs/swagger'; import { FileValidationPipe } from 'src/shared/pipe/file-validation.pipe'; import { fileInterceptor } from 'src/shared/interceptors/file-save.interceptor'; import { CreateTownDto } from './dto/create-town.dto'; import { UpdateTownDto } from './dto/update-town.dto'; @Controller('town') @ApiTags('Agregar un pueblo') export class TownController { constructor(private readonly townService: TownService) {} @Post() create(@Body() createTownDto: CreateTownDto) { return this.townService.create(createTownDto); @UseInterceptors(fileInterceptor('image', 'static/towns/', ['.jpg', '.jpeg', '.png'])) async create(@UploadedFile(new FileValidationPipe()) file, @Body() createTownDto: CreateTownDto) { try { createTownDto.imageName = file.filename; await this.townService.create(createTownDto); return { message: 'Town created successfully' }; } catch (error) { throw error; } } @Get() Loading @@ -25,16 +26,6 @@ export class TownController { return this.townService.findAll(); } @Get(':id') findOne(@Param('id') id: string) { return this.townService.findOne(+id); } @Patch(':id') update(@Param('id') id: string, @Body() updateTownDto: UpdateTownDto) { return this.townService.update(+id, updateTownDto); } @Delete(':id') remove(@Param('id') id: string) { return this.townService.remove(+id); Loading