From 1c9eb5cb48b7f4b9bff96bb5ee1c774f13f9b258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Mon, 14 Oct 2024 23:05:42 -0600 Subject: [PATCH] fix agregando url base a las imagenes y filtrando por language --- backend/src/route/route.controller.ts | 5 ++-- backend/src/route/route.service.ts | 35 +++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/backend/src/route/route.controller.ts b/backend/src/route/route.controller.ts index 4e51670c..a4ea8743 100644 --- a/backend/src/route/route.controller.ts +++ b/backend/src/route/route.controller.ts @@ -52,9 +52,10 @@ export class RouteController { @ApiParam({ name: 'idRoute', type: Number }) @ApiBearerAuth('jwt') @UseGuards(AuthUserGuard) - async getRoute(@Param('idRoute') idRoute: number, @Req() req: CustomUserRequest) { + async getRoute(@Param('idRoute') idRoute: number, @Param('lang') lang: LANGUAGES, @Req() req: CustomUserRequest) { const { email } = req.user; - return await this.routeService.getRouteById(idRoute, email); + + return await this.routeService.getRouteById(idRoute, email, lang); } @Patch('/:idRoute') diff --git a/backend/src/route/route.service.ts b/backend/src/route/route.service.ts index 1b4c9df1..048ca136 100644 --- a/backend/src/route/route.service.ts +++ b/backend/src/route/route.service.ts @@ -15,6 +15,8 @@ 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'; +import { TravelPlace } from 'src/travel-place/entities/travel-place.entity'; +import { ServerConstants } from 'src/constants/server.contants'; @Injectable() export class RouteService { @@ -87,7 +89,7 @@ export class RouteService { await this.travelPlaceService.create(createTravelPlace); } - return await this.getRouteById(idRoute, email); + return await this.getRouteById(idRoute, email, language); } async getRouteAndPlacesByUser(email: string, routeStatus: RouteStatus) { @@ -103,9 +105,38 @@ export class RouteService { await this.routeRepository.update({ idRoute }, { status }); } - async getRouteById(idRoute: number, email: string) { + async getRouteById(idRoute: number, email: string, lang: LANGUAGES) { const user: User = await this.userService.findOne(email); const res = await this.routeRepository.findOneBy({ idRoute, user }); + + if (res && res.travelPlace) { + res.travelPlace = res.travelPlace.map((place) => { + place.place.categories = place.place.categories.filter((category) => category.language === lang); + return place; + }); + + res.travelPlace = res.travelPlace.map((travelPlace: TravelPlace) => { + return { + travelPlaceId: travelPlace.travelPlaceId, + idPlace: travelPlace.place.idPlace, + available: travelPlace.place.available, + latitude: travelPlace.place.latitude, + longitude: travelPlace.place.longitude, + imageName: `${ServerConstants.HOST}/places/${travelPlace.place.imageName}`, + name: travelPlace.place.name, + openAt: travelPlace.place.openAt, + closeAt: travelPlace.place.closeAt, + startDate: travelPlace.startDate, + endDate: travelPlace.endDate, + categories: travelPlace.place.categories, + address: travelPlace.place.address, + done: travelPlace.done, + route: travelPlace.route, + place: { ...travelPlace.place, imageName: `${ServerConstants.HOST}/places/${travelPlace.place.imageName}` }, + }; + }); + } + return res; } } -- GitLab