diff --git a/backend/src/place/entities/available-date.entity.ts b/backend/src/place/entities/available-date.entity.ts index f6c3737c43137e701c687b0336a290b5b1424e20..e611bb505cbe7cc6b86c7d4ff0ff1e0490911b89 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 5a1383084235f3f10c181c94068175300d19b746..595e1f252b75d14c9a756221cb4c39065fb8d127 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) diff --git a/backend/src/place/place.service.ts b/backend/src/place/place.service.ts index d13a40dce89040c710d4c542cb54ae964e04aee2..312ff457379bd5cfc1b3dcc3ede402b488504c70 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, + }); } } @@ -202,9 +206,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'], ); } }