Commit 4eea0c5a authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Merge branch 'main' into 'main'

Corrigiendo bug que no permitia actualizar custom dates

See merge request pueblosmagicosconia!68
parents b2958ce4 a142745a
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
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;
+1 −1
Original line number Diff line number Diff line
@@ -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)
+13 −4
Original line number Diff line number Diff line
@@ -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'],
      );
    }
  }