Loading backend/src/place/dto/get-place.dto.ts +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() Loading @@ -10,7 +11,7 @@ export class GetPlaceDto { @ApiProperty() description: string; @ApiProperty() available: string; available: Available; @ApiProperty() imageName: string; @ApiProperty() Loading backend/src/place/place.service.ts +19 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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); } } backend/src/place/utils/isPlaceOpen.ts 0 → 100644 +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; }; backend/src/pointOfInterest/PointOfInterest.service.ts +24 −28 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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> `; } Loading backend/src/pointOfInterest/entities/PointOfInterestTraduction.entity.ts +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ export class PointOfInterestTraduction { @Column({ nullable: false }) content: string; @Column({ nullable: false }) @Column({ nullable: true }) directions: string; @Column() Loading Loading
backend/src/place/dto/get-place.dto.ts +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() Loading @@ -10,7 +11,7 @@ export class GetPlaceDto { @ApiProperty() description: string; @ApiProperty() available: string; available: Available; @ApiProperty() imageName: string; @ApiProperty() Loading
backend/src/place/place.service.ts +19 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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); } }
backend/src/place/utils/isPlaceOpen.ts 0 → 100644 +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; };
backend/src/pointOfInterest/PointOfInterest.service.ts +24 −28 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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> `; } Loading
backend/src/pointOfInterest/entities/PointOfInterestTraduction.entity.ts +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ export class PointOfInterestTraduction { @Column({ nullable: false }) content: string; @Column({ nullable: false }) @Column({ nullable: true }) directions: string; @Column() Loading