From 00827ef4a1c9824250a9b39e789329e4419966d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Wed, 11 Sep 2024 18:00:57 -0600 Subject: [PATCH 1/2] corrigiendo relacion available-date y place --- backend/src/place/entities/available-date.entity.ts | 8 ++++---- backend/src/place/entities/place.entity.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/place/entities/available-date.entity.ts b/backend/src/place/entities/available-date.entity.ts index f6c3737c..e611bb50 100644 --- a/backend/src/place/entities/available-date.entity.ts +++ b/backend/src/place/entities/available-date.entity.ts @@ -1,14 +1,14 @@ -import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; +import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm'; import { Place } from './place.entity'; @Entity() export class AvailableDate { - @PrimaryGeneratedColumn() - idAvailableDate: number; + @PrimaryColumn() + idPlace: number; @JoinColumn({ name: 'idPlace' }) @ManyToOne(() => Place, (place) => place.availableDates, { nullable: false }) - idPlace: Place; + place: Place; @Column() startDate: Date; diff --git a/backend/src/place/entities/place.entity.ts b/backend/src/place/entities/place.entity.ts index 5a138308..595e1f25 100644 --- a/backend/src/place/entities/place.entity.ts +++ b/backend/src/place/entities/place.entity.ts @@ -27,7 +27,7 @@ export class Place { @OneToMany(() => PointOfInterest, (point) => point.idPoint) points: PointOfInterest[]; - @OneToMany(() => AvailableDate, (available) => available.idPlace) + @OneToMany(() => AvailableDate, (available) => available.place) availableDates: AvailableDate[]; @ManyToMany(() => Category) -- GitLab From a192bd6495eae9803bc473f8ffa21effc9a3318e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Wed, 11 Sep 2024 18:01:22 -0600 Subject: [PATCH 2/2] corrigiendo bug que no permitia actualizar custom dates --- backend/src/place/place.service.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/src/place/place.service.ts b/backend/src/place/place.service.ts index 6f258c3c..f73709ca 100644 --- a/backend/src/place/place.service.ts +++ b/backend/src/place/place.service.ts @@ -76,7 +76,11 @@ export class PlaceService { await this.placeTraductionRepository.insert(createTradEs); await this.placeTraductionRepository.insert(createTradEn); if (createPlaceDto.available === Available.CUSTOM) { - await this.availableDateRepository.insert({ ...createDate, idPlace: insertedPlace }); + await this.availableDateRepository.insert({ + ...createDate, + place: insertedPlace, + idPlace: insertedPlace.idPlace, + }); } } @@ -201,9 +205,14 @@ export class PlaceService { // Update available date if necessary if (updatePlaceReqDto.available === Available.CUSTOM) { - await this.availableDateRepository.update( - { idPlace: place }, - { startDate: updatePlaceReqDto.startDate, endDate: updatePlaceReqDto.endDate }, + await this.availableDateRepository.upsert( + { + idPlace: place.idPlace, + place: place, + startDate: updatePlaceReqDto.startDate, + endDate: updatePlaceReqDto.endDate, + }, + ['idPlace'], ); } } -- GitLab