From 06261915bdf6e64d1504e42bbff71c203bf1e172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:02:22 -0600 Subject: [PATCH] corrigiendo primary keys de entidad visited --- backend/src/route/route.service.ts | 1 + backend/src/visited/entities/visited.entity.ts | 7 ++++--- backend/src/visited/visited.service.ts | 7 ++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/src/route/route.service.ts b/backend/src/route/route.service.ts index e624089e..1b2cd86a 100644 --- a/backend/src/route/route.service.ts +++ b/backend/src/route/route.service.ts @@ -72,5 +72,6 @@ export class RouteService { for (const place of placesChooen) { await this.createRoute(email, idTown, place.idPlace, new Date(), new Date()); } + return placesChooen; } } diff --git a/backend/src/visited/entities/visited.entity.ts b/backend/src/visited/entities/visited.entity.ts index 81de0fed..2ed305b3 100644 --- a/backend/src/visited/entities/visited.entity.ts +++ b/backend/src/visited/entities/visited.entity.ts @@ -1,15 +1,16 @@ import { Place } from 'src/place/entities/place.entity'; import { User } from 'src/user/entities/user.entity'; -import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm'; +import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; @Entity() export class Visited { - @PrimaryColumn() + @PrimaryGeneratedColumn() + idVisited: number; + @ManyToOne(() => Place, (place) => place.idPlace, { eager: true }) @JoinColumn({ name: 'place' }) place: Place; - @PrimaryColumn() @ManyToOne(() => User, (user) => user.email) @JoinColumn({ name: 'user' }) user: User; diff --git a/backend/src/visited/visited.service.ts b/backend/src/visited/visited.service.ts index 722905b5..dbe0fa9e 100644 --- a/backend/src/visited/visited.service.ts +++ b/backend/src/visited/visited.service.ts @@ -21,15 +21,12 @@ export class VisitedService { const user: User = await this.userService.findOne(email); if (!place || !user) throw new BadRequestException('Place or user not found'); - await this.visitedRepository.upsert( - { place, user, rating: createVisitedDto.rating }, - { conflictPaths: ['place', 'user'] }, - ); + await this.visitedRepository.save({ place, user, rating: createVisitedDto.rating }); } async getVisitedByUser(email: string): Promise { const user: User = await this.userService.findOne(email); - return this.visitedRepository.find({ + return await this.visitedRepository.find({ where: { user }, relations: ['place', 'place.categories'], }); -- GitLab