Commit 34aa996a authored by Diego Iván's avatar Diego Iván
Browse files

agregando endpoints para obtener todas las rutas, actualizar rutas y obtener por id

parent 7ac0164c
Loading
Loading
Loading
Loading
+26 −8
Original line number Diff line number Diff line
import { Controller, Param, UseGuards, Req, Query, Body, Post, Get } from '@nestjs/common';
import { Controller, Param, UseGuards, Req, Query, Body, Post, Get, Patch } from '@nestjs/common';
import { RouteService } from './route.service';
import { ApiBearerAuth, ApiBody, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { LANGUAGES } from 'src/shared/enum/languages.enum';
import { AuthUserGuard } from 'src/auth/user/authUser.guard';
import { CustomUserRequest } from 'src/auth/user/interface/customUserReq';
import { CreateRouteReq } from './dto/create-route-req';
import { RouteStatus } from './entities/route.entity';
import { UpdateRouteStatusDto } from './dto/updateRouteStatus.dto';

@Controller('route')
@ApiTags('route')
export class RouteController {
  constructor(private readonly routeService: RouteService) {}

  @Post('recommend/:idTown')
  @ApiQuery({ name: 'lang', type: String })
  @Post('/:idTown')
  @ApiParam({ name: 'idTown', type: Number })
  @ApiBody({ type: CreateRouteReq })
  @ApiBearerAuth('jwt')
@@ -33,13 +34,30 @@ export class RouteController {
    );
  }

  @Get('recommend/:idTown')
  @ApiQuery({ name: 'lang', type: String })
  @ApiParam({ name: 'idTown', type: Number })
  @Get('')
  @ApiQuery({ name: 'routeStatus', type: String, schema: { enum: Object.values(RouteStatus) } })
  @ApiBearerAuth('jwt')
  @UseGuards(AuthUserGuard)
  async recommendRouteGet(@Req() req: CustomUserRequest, @Query('routeStatus') routeStatus: RouteStatus) {
    const { email } = req.user;
    return await this.routeService.getRouteAndPlacesByUser(email, routeStatus);
  }

  @Get('/:idRoute')
  @ApiParam({ name: 'idRoute', type: Number })
  @ApiBearerAuth('jwt')
  @UseGuards(AuthUserGuard)
  async recommendRouteGet(@Req() req: CustomUserRequest, @Query('lang') lang: string, @Param('idTown') idTown: number) {
  async getRoute(@Param('idRoute') idRoute: number, @Req() req: CustomUserRequest) {
    const { email } = req.user;
    return await this.routeService.getRouteAndPlacesByUser(email, lang as LANGUAGES, idTown);
    return await this.routeService.getRouteById(idRoute, email);
  }

  @Patch('/:idRoute')
  @ApiParam({ name: 'idRoute', type: Number })
  @ApiBody({ type: UpdateRouteStatusDto, description: 'accepted, rejected, pending' })
  @ApiBearerAuth('jwt')
  @UseGuards(AuthUserGuard)
  async updateRoute(@Body() updateRouteStatusDto: UpdateRouteStatusDto, @Param('idRoute') idRoute: number) {
    return await this.routeService.updateRoute(idRoute, updateRouteStatusDto.status);
  }
}