Commit 6d97f964 authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Merge branch 'main' into 'main'

Agregando campos faltantes en las queries para obtener Places

See merge request ltrpro/pueblosmagicosconia!32
parents 43301944 5bec973e
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
import { Available } from 'src/pointOfInterest/enum/available.enum';
import { Town } from 'src/town/entities/town.entity';
import { Place } from '../entities/place.entity';

export class GetPlaceDto {
  idTown: number;
  idPlace: Place;
  available: Available;
  name: string;
  description: string;
  imageName: string;
  idTown: Town;
  coords: string;
  openAt: number;
  closeAt: number;
+3 −3
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@ export class PlaceController {
    }
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.placeService.findOne(+id);
  @Get(':idPlace')
  findOne(@Param('idPlace') idPlace: number) {
    return this.placeService.findOneAndTradAndAvailable(idPlace);
  }
}
+43 −3
Original line number Diff line number Diff line
@@ -81,16 +81,19 @@ export class PlaceService {
        'place.closeAt AS closeAt',
        'availableDate.startDate AS startDate',
        'availableDate.endDate AS endDate',
        'place.available AS available',
        'place.idTown AS idTown',
      ])
      .where('place.idTown = :idTown', { idTown: idTown })
      .andWhere('placeTrad.language = :language', { language: lang })
      .getRawMany();
    const places: GetPlaceDto[] = res.map((place) => {
      return {
        idTown: place.idTown,
        idPlace: place.idPlace,
        available: place.available,
        description: place.description,
        coords: place.coords,
        idTown: place.idTown,
        imageName: `${ServerConstants.HOST}/places/${place.imageName}`,
        name: place.name,
        openAt: place.openAt,
@@ -103,7 +106,44 @@ export class PlaceService {
  }

  async findOne(id: number) {
    const place = await this.placeRepository.findOneBy({ idPlace: id });
    return place;
    return await this.placeRepository.findOneBy({ idPlace: id });
  }

  async findOneAndTradAndAvailable(idPlace: number) {
    const place: GetPlaceDto = await this.dataSource
      .getRepository(PlaceTraduction)
      .createQueryBuilder('placeTrad')
      .leftJoin('placeTrad.idPlace', 'place')
      .leftJoin('place.availableDates', 'availableDate')
      .select([
        'place.idPlace AS idPlace',
        'place.name AS name',
        'place.imageName AS imageName',
        'placeTrad.language AS language',
        'placeTrad.description AS description',
        'place.coords AS coords',
        'place.openAt AS openAt',
        'place.closeAt AS closeAt',
        'availableDate.startDate AS startDate',
        'availableDate.endDate AS endDate',
        'place.idTown AS idTown',
        'place.available AS available',
      ])
      .where('place.idPlace = :idPlace', { idPlace: idPlace })
      .getRawOne();

    return {
      idTown: place.idTown,
      idPlace: place.idPlace,
      available: place.available,
      description: place.description,
      coords: place.coords,
      imageName: `${ServerConstants.HOST}/places/${place.imageName}`,
      name: place.name,
      openAt: place.openAt,
      closeAt: place.closeAt,
      startDate: place.startDate,
      endDate: place.endDate,
    };
  }
}