diff --git a/backend/src/route/route.controller.ts b/backend/src/route/route.controller.ts index 4e51670c8b46caeb5dea8c2645aa124040bcf1ec..a4ea87438c42753393e31b34acec94ffc9f850d1 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 1b4c9df16ecf65cd5b9320dea78ab078babaa7fc..048ca136addc5f9e572be9687445472eefef8aa8 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; } }