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); } } 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); } }