Commit c1696a3a authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Merge branch 'main' into 'main'

corrigiendo primary keys de entidad visited

See merge request !60
parents 49815fdc 9a3d7a28
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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;
  }
}
+4 −3
Original line number Diff line number Diff line
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;
+2 −5
Original line number Diff line number Diff line
@@ -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<Visited[]> {
    const user: User = await this.userService.findOne(email);
    return this.visitedRepository.find({
    return await this.visitedRepository.find({
      where: { user },
      relations: ['place', 'place.categories'],
    });