Commit 6a3da0d1 authored by Diego Iván's avatar Diego Iván
Browse files

agregando endpoint para agregar un town

parent faa5f679
Loading
Loading
Loading
Loading
+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()
@@ -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);