From 8130bd19d0ff2fa50f46b3ffc9e46eb27f7d1cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:36:20 -0600 Subject: [PATCH 1/4] agregando status a una ruta --- backend/src/route/entities/route.entity.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/route/entities/route.entity.ts b/backend/src/route/entities/route.entity.ts index 30f9a975..566b3da5 100644 --- a/backend/src/route/entities/route.entity.ts +++ b/backend/src/route/entities/route.entity.ts @@ -2,7 +2,7 @@ import { Town } from 'src/town/entities/town.entity'; import { TravelPlace } from 'src/travel-place/entities/travel-place.entity'; import { User } from 'src/user/entities/user.entity'; import { PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Entity, OneToMany } from 'typeorm'; -enum RouteStatus { +export enum RouteStatus { PENDING = 'pending', ACCEPTED = 'accepted', REJECTED = 'rejected', -- GitLab From f17c068c43fae5bf7f4e4b3134036db3a3bb2bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:36:40 -0600 Subject: [PATCH 2/4] dto para actualizar un status de una ruta --- backend/src/route/dto/updateRouteStatus.dto.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 backend/src/route/dto/updateRouteStatus.dto.ts diff --git a/backend/src/route/dto/updateRouteStatus.dto.ts b/backend/src/route/dto/updateRouteStatus.dto.ts new file mode 100644 index 00000000..fba15c88 --- /dev/null +++ b/backend/src/route/dto/updateRouteStatus.dto.ts @@ -0,0 +1,7 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { RouteStatus } from '../entities/route.entity'; + +export class UpdateRouteStatusDto { + @ApiProperty({ enum: RouteStatus, enumName: 'RouteStatus', description: 'accepted, pending, rejected' }) + status: RouteStatus; +} -- GitLab From 7ac0164cdf257c19245ff4d45cbc9b1bb4109c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:37:13 -0600 Subject: [PATCH 3/4] agregando metodos updateRoute y getRouteById --- backend/src/route/route.service.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/backend/src/route/route.service.ts b/backend/src/route/route.service.ts index 572a1838..b4acebdc 100644 --- a/backend/src/route/route.service.ts +++ b/backend/src/route/route.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { InjectDataSource, InjectRepository } from '@nestjs/typeorm'; -import { Route } from './entities/route.entity'; +import { Route, RouteStatus } from './entities/route.entity'; import { DataSource, Repository } from 'typeorm'; import { User } from 'src/user/entities/user.entity'; import { Town } from 'src/town/entities/town.entity'; @@ -14,6 +14,7 @@ import { Visited } from 'src/visited/entities/visited.entity'; import { RecommendPlace } from './dto/recommend-route.dto'; import { CreateRouteDto } from './dto/create-route.dto'; import { CreateTravelPlaceDto } from 'src/travel-place/dto/create-travel-place.dto'; +import { UserService } from 'src/user/user.service'; @Injectable() export class RouteService { @@ -25,6 +26,7 @@ export class RouteService { @InjectDataSource() private dataSource: DataSource, private readonly placeService: PlaceService, private readonly visitedService: VisitedService, + private readonly userService: UserService, ) {} async recommend(idTown: number, email: string, language: LANGUAGES, start, end) { @@ -87,12 +89,21 @@ export class RouteService { } } - async getRouteAndPlacesByUser(email: string, language: LANGUAGES, idTown: number) { - const res = await this.routeRepository.findOne({ + async getRouteAndPlacesByUser(email: string, routeStatus: RouteStatus) { + const res = await this.routeRepository.find({ relations: ['travelPlace'], - where: { user: { email }, town: { townId: idTown } }, + where: { user: { email }, status: routeStatus }, }); return res; } + + async updateRoute(idRoute: number, status: RouteStatus) { + await this.routeRepository.update({ idRoute }, { status }); + } + + async getRouteById(idRoute: number, email: string) { + const user: User = await this.userService.findOne(email); + return await this.routeRepository.findOneBy({ idRoute, user }); + } } -- GitLab From 34aa996aba87e32364bd38990cdbaa854224fe25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:37:44 -0600 Subject: [PATCH 4/4] agregando endpoints para obtener todas las rutas, actualizar rutas y obtener por id --- backend/src/route/route.controller.ts | 34 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/backend/src/route/route.controller.ts b/backend/src/route/route.controller.ts index 08591cb8..7586762f 100644 --- a/backend/src/route/route.controller.ts +++ b/backend/src/route/route.controller.ts @@ -1,18 +1,19 @@ -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); } } -- GitLab