From 8f9e7c4833e78165c133b20d46c68beb11f6cfd0 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 17:16:52 -0600 Subject: [PATCH] agregando town y tags en la respuesta de route --- backend/src/place/entities/place.entity.ts | 2 +- backend/src/route/entities/route.entity.ts | 2 +- backend/src/route/route.controller.ts | 9 +++++++-- backend/src/route/route.service.ts | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/src/place/entities/place.entity.ts b/backend/src/place/entities/place.entity.ts index 595e1f25..b4ed14c7 100644 --- a/backend/src/place/entities/place.entity.ts +++ b/backend/src/place/entities/place.entity.ts @@ -30,7 +30,7 @@ export class Place { @OneToMany(() => AvailableDate, (available) => available.place) availableDates: AvailableDate[]; - @ManyToMany(() => Category) + @ManyToMany(() => Category, { eager: true }) @JoinTable() categories: Category[]; diff --git a/backend/src/route/entities/route.entity.ts b/backend/src/route/entities/route.entity.ts index 566b3da5..fd14cf7e 100644 --- a/backend/src/route/entities/route.entity.ts +++ b/backend/src/route/entities/route.entity.ts @@ -18,7 +18,7 @@ export class Route { user: User; @JoinColumn({ name: 'town' }) - @ManyToOne(() => Town, (town) => town.townId, { nullable: false }) + @ManyToOne(() => Town, (town) => town.townId, { nullable: false, eager: true }) town: Town; @OneToMany(() => TravelPlace, (travelPlace) => travelPlace.route, { eager: true }) diff --git a/backend/src/route/route.controller.ts b/backend/src/route/route.controller.ts index 54de3b40..4e51670c 100644 --- a/backend/src/route/route.controller.ts +++ b/backend/src/route/route.controller.ts @@ -39,8 +39,13 @@ export class RouteController { @ApiBearerAuth('jwt') @UseGuards(AuthUserGuard) async getRecommendRoute(@Req() req: CustomUserRequest, @Query('routeStatus') routeStatus: RouteStatus) { - const { email } = req.user; - return await this.routeService.getRouteAndPlacesByUser(email, routeStatus); + try { + const { email } = req.user; + return await this.routeService.getRouteAndPlacesByUser(email, routeStatus); + } catch (error) { + console.log(error); + return error; + } } @Get('/:idRoute') diff --git a/backend/src/route/route.service.ts b/backend/src/route/route.service.ts index baf2dd22..1b4c9df1 100644 --- a/backend/src/route/route.service.ts +++ b/backend/src/route/route.service.ts @@ -105,6 +105,7 @@ export class RouteService { async getRouteById(idRoute: number, email: string) { const user: User = await this.userService.findOne(email); - return await this.routeRepository.findOneBy({ idRoute, user }); + const res = await this.routeRepository.findOneBy({ idRoute, user }); + return res; } } -- GitLab