Commit 0dc6a243 authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Merge branch 'main' into 'main'

Validando que un lugar esté abierto para crear una ruta

See merge request !73
parents 43030677 2d45a92c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
import { ApiProperty } from '@nestjs/swagger';
import { Available } from 'src/pointOfInterest/enum/available.enum';

export class GetPlaceDto {
  @ApiProperty()
@@ -10,7 +11,7 @@ export class GetPlaceDto {
  @ApiProperty()
  description: string;
  @ApiProperty()
  available: string;
  available: Available;
  @ApiProperty()
  imageName: string;
  @ApiProperty()
+19 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import { Available } from 'src/pointOfInterest/enum/available.enum';
import { UpdatePlaceReqDto } from './dto/update-place.req.dto';
import { Category } from 'src/category/entities/category.entity';
import { Visited } from 'src/visited/entities/visited.entity';
import { isPlaceOpen } from './utils/isPlaceOpen';

@Injectable()
export class PlaceService {
@@ -230,4 +231,22 @@ export class PlaceService {
    // podemos hacerlo en la query
    return places.filter((place) => !visitedIds.includes(place.idPlace));
  }

  async findPlacesNotVisitedByUserAndOpen(email: string, lang: LANGUAGES, idTown: number): Promise<GetPlaceDto[]> {
    const places: GetPlaceDto[] = await this.findPlacesNotVisitedByUser(email, lang, idTown);

    const placesWithAvailability = await Promise.all(
      places.map(async (place) => {
        if (place.available === Available.CUSTOM) {
          const availableDate = await this.availableDateRepository.findOneBy({ place });
          const isOpen = isPlaceOpen(place.available, availableDate?.startDate, availableDate?.endDate);
          return isOpen ? place : null;
        } else {
          return isPlaceOpen(place.available, null, null) ? place : null;
        }
      }),
    );

    return placesWithAvailability.filter((place) => place !== null);
  }
}
+10 −0
Original line number Diff line number Diff line
import { Available, availableToDays } from 'src/pointOfInterest/enum/available.enum';

export const isPlaceOpen = (available: Available, startDate?: Date, endDate?: Date): boolean => {
  const curDayName: string = new Date().toLocaleDateString('en-US', { weekday: 'long' });
  if (available !== Available.CUSTOM) {
    return availableToDays[available].includes(curDayName);
  }
  const curDate: Date = new Date();
  return curDate >= startDate && curDate <= endDate;
};
+24 −28
Original line number Diff line number Diff line
@@ -151,21 +151,19 @@ export class PointOfInterestService {
    if (!place) {
      throw new BadRequestException('Place not found');
    }
    let points: printPointInfo[] = await Promise.all(pointsId.map(async (idPoint)=>{
      let point = await this.dataSource
    const points: printPointInfo[] = await Promise.all(
      pointsId.map(async (idPoint) => {
        const point = await this.dataSource
          .getRepository(PointOfInterest)
          .createQueryBuilder('point')
          .leftJoin('point.idPlace', 'place')
      .select([
        'point.idPoint as idPoint',
        'place.name as namePlace',
        'point.name as name',
      ])
          .select(['point.idPoint as idPoint', 'place.name as namePlace', 'point.name as name'])
          .where('place.idPlace = :idPlace', { idPlace })
          .andWhere('point.idPoint = :idPoint', { idPoint })
          .getRawOne();
        return point;
    }))
      }),
    );
    return points;
  }

@@ -194,16 +192,14 @@ export class PointOfInterestService {

      cardsHtml += `
        <div class="card">
          <img class="background" src="data:image/jpeg;base64,${
            readFileSync('./src/pointOfInterest/utils/zac.jpeg').toString('base64')
          }"/>
          <img class="background" src="data:image/jpeg;base64,${readFileSync(
            './src/pointOfInterest/utils/zac.jpeg',
          ).toString('base64')}"/>
          <div class="content">
            <h3>${point.namePlace}</h3>
            <p>${point.name}</p>
          </div>
          <img src="data:image/jpeg;base64,${
            readFileSync(filePath).toString('base64')
          }" class="qr-code"/>
          <img src="data:image/jpeg;base64,${readFileSync(filePath).toString('base64')}" class="qr-code"/>
        </div>
      `;
    }
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ export class PointOfInterestTraduction {

  @Column({ nullable: false })
  content: string;
  @Column({ nullable: false })
  @Column({ nullable: true })
  directions: string;

  @Column()
Loading