From 170db9f4f42dc2c6bbc10afef56232c138bf247a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:43:40 -0600 Subject: [PATCH 1/8] formatenado codigo --- .../PointOfInterest.service.ts | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/backend/src/pointOfInterest/PointOfInterest.service.ts b/backend/src/pointOfInterest/PointOfInterest.service.ts index 2ad45cb7..ed2b793a 100644 --- a/backend/src/pointOfInterest/PointOfInterest.service.ts +++ b/backend/src/pointOfInterest/PointOfInterest.service.ts @@ -146,64 +146,60 @@ export class PointOfInterestService { return point; } - async findAllByIds(idPlace:number, pointsId: number[]): Promise { + async findAllByIds(idPlace: number, pointsId: number[]): Promise { const place = await this.placeService.findOne(idPlace); if (!place) { throw new BadRequestException('Place not found'); } - let points: printPointInfo[] = await Promise.all(pointsId.map(async (idPoint)=>{ - let 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', - ]) - .where('place.idPlace = :idPlace', { idPlace }) - .andWhere('point.idPoint = :idPoint', {idPoint}) - .getRawOne(); - return point; - })) + 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']) + .where('place.idPlace = :idPlace', { idPlace }) + .andWhere('point.idPoint = :idPoint', { idPoint }) + .getRawOne(); + return point; + }), + ); return points; } - async generatePdf(idPlace:number, pointsId: number[]): Promise { + async generatePdf(idPlace: number, pointsId: number[]): Promise { const points = await this.findAllByIds(idPlace, pointsId); const htmlContent = this.generateHtml(points); const browser = await puppeteer.launch(); const page = await browser.newPage(); - + await page.setContent(htmlContent); const pdfBuffer = await page.pdf({ format: 'A4', margin: { top: '10mm', bottom: '10mm', left: '10mm', right: '10mm' }, // Márgenes }); - + await browser.close(); - + return Buffer.from(pdfBuffer); } private generateHtml(points: printPointInfo[]): string { let cardsHtml = ''; - for(const point of points) { + for (const point of points) { const filePath = join(ServerConstants.ROOT_STATIC_PATH, 'qr', point.idPoint.toString() + '.png'); - + cardsHtml += `
- +

${point.namePlace}

${point.name}

- +
`; } -- GitLab From bb2ec7b95437e6883074ccfdcad754f9eca3e6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:34:42 -0600 Subject: [PATCH 2/8] =?UTF-8?q?agregando=20funcion=20para=20validar=20si?= =?UTF-8?q?=20un=20Place=20est=C3=A1=20abierto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/place/utils/isPlaceOpen.ts | 10 ++++++++++ backend/src/user/user.service.ts | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 backend/src/place/utils/isPlaceOpen.ts diff --git a/backend/src/place/utils/isPlaceOpen.ts b/backend/src/place/utils/isPlaceOpen.ts new file mode 100644 index 00000000..0f64d5d8 --- /dev/null +++ b/backend/src/place/utils/isPlaceOpen.ts @@ -0,0 +1,10 @@ +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; +}; diff --git a/backend/src/user/user.service.ts b/backend/src/user/user.service.ts index 63b2c3cc..62e7b4d5 100644 --- a/backend/src/user/user.service.ts +++ b/backend/src/user/user.service.ts @@ -17,8 +17,9 @@ export class UserService { private categoryService: CategoryService, ) {} - async findOne(email: string) { - return await this.userRepository.findOneBy({ email }); + async findOne(email: string): Promise { + const user = await this.userRepository.findOneBy({ email }); + return user; } async create(createUserDto: CreateUserDto) { -- GitLab From 5f338d633d85de2688cfee70e3b88b4d17b336e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:35:09 -0600 Subject: [PATCH 3/8] corrigiendo funcion que valida los horarios de una ruta --- backend/src/route/utils/recommendations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/route/utils/recommendations.ts b/backend/src/route/utils/recommendations.ts index 8fb0aa2e..971d1134 100644 --- a/backend/src/route/utils/recommendations.ts +++ b/backend/src/route/utils/recommendations.ts @@ -93,7 +93,7 @@ export class RecommendationsSystem { for (const place of validRecommendations) { // Verificar si el lugar está abierto y si se puede acomodar dentro del horario const maxStart = Math.max(currentTime, place.openAt); - const minEnd = Math.min((currentTime + 2) % 24, place.closeAt); + const minEnd = Math.min(this.end, place.closeAt); if (minEnd - 2 >= maxStart) { // Verificar si aún hay tiempo suficiente en el rango total de la ruta -- GitLab From dac2f8522c5a650d718d85eb195c6184b8e877e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:35:42 -0600 Subject: [PATCH 4/8] agregando mapa de disponibilidad a dia de la semana --- backend/src/pointOfInterest/enum/available.enum.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/pointOfInterest/enum/available.enum.ts b/backend/src/pointOfInterest/enum/available.enum.ts index 5449782a..3c70ab58 100644 --- a/backend/src/pointOfInterest/enum/available.enum.ts +++ b/backend/src/pointOfInterest/enum/available.enum.ts @@ -4,3 +4,9 @@ export enum Available { WEEKDAYS = 'weekdays', CUSTOM = 'custom', } + +export const availableToDays = { + [Available.WEEKEND]: ['Saturday', 'Sunday'], + [Available.ALL_DAYS]: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'], + [Available.WEEKDAYS]: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], +}; -- GitLab From 450232447030b1b2d5c4a8d0f4beee2268b0dba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:36:10 -0600 Subject: [PATCH 5/8] cambiando para solo obtener los Places abiertos --- backend/src/route/route.service.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/src/route/route.service.ts b/backend/src/route/route.service.ts index 66a73c41..572a1838 100644 --- a/backend/src/route/route.service.ts +++ b/backend/src/route/route.service.ts @@ -31,7 +31,11 @@ export class RouteService { // Obtener los visitados y los candidatos const town: Town = await this.townRepository.findOneBy({ townId: idTown }); const user: User = await this.userRepository.findOneBy({ email }); - const placesNotVisited: GetPlaceDto[] = await this.placeService.findPlacesNotVisitedByUser(email, language, idTown); + const placesNotVisited: GetPlaceDto[] = await this.placeService.findPlacesNotVisitedByUserAndOpen( + email, + language, + idTown, + ); const visited: Visited[] = await this.visitedService.getVisitedByUser(email); const placesMapped: RecommendPlace[] = placesNotVisited.map((place) => { return { @@ -43,15 +47,13 @@ export class RouteService { }; }); - const visitedMapped: RecommendPlace[] = visited.map((visit) => { - return { - idPlace: visit.place.idPlace, - openAt: visit.place.openAt, - closeAt: visit.place.closeAt, - categories: visit.place.categories.map((category) => category.idCategory), - rating: visit.rating, - }; - }); + const visitedMapped: RecommendPlace[] = visited.map((visit) => ({ + idPlace: visit.place.idPlace, + openAt: visit.place.openAt, + closeAt: visit.place.closeAt, + categories: visit.place.categories.map((category) => category.idCategory), + rating: visit.rating, + })); const system = new RecommendationsSystem(visitedMapped, placesMapped, start, end); const chosen: RecommendPlace[] = system.recommend(); @@ -68,8 +70,10 @@ export class RouteService { const place = await this.placeService.findOneAndTradAndAvailable(curRecommended.idPlace, language); const endDate = new Date(); endDate.setHours(curRecommended.closeAt); + endDate.setMinutes(0); const startDate = new Date(); startDate.setHours(curRecommended.openAt); + startDate.setMinutes(0); const createTravelPlace: CreateTravelPlaceDto = { ...place, -- GitLab From 421dd30786159bd75fa3446b133336b9c75cc036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:36:38 -0600 Subject: [PATCH 6/8] agregando metodo findPlacesNotVisitedByUserAndOpen --- backend/src/place/place.service.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/src/place/place.service.ts b/backend/src/place/place.service.ts index 312ff457..115604f7 100644 --- a/backend/src/place/place.service.ts +++ b/backend/src/place/place.service.ts @@ -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 { + 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); + } } -- GitLab From 29bd9f9186e0d174a54acdfae9f2e59034a67331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:37:01 -0600 Subject: [PATCH 7/8] volviendo las direcciones nullables --- .../entities/PointOfInterestTraduction.entity.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/pointOfInterest/entities/PointOfInterestTraduction.entity.ts b/backend/src/pointOfInterest/entities/PointOfInterestTraduction.entity.ts index f6cc23f3..858f8103 100644 --- a/backend/src/pointOfInterest/entities/PointOfInterestTraduction.entity.ts +++ b/backend/src/pointOfInterest/entities/PointOfInterestTraduction.entity.ts @@ -12,7 +12,7 @@ export class PointOfInterestTraduction { @Column({ nullable: false }) content: string; - @Column({ nullable: false }) + @Column({ nullable: true }) directions: string; @Column() -- GitLab From 296709e87143be1eba085637d19e204ed54450de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:37:15 -0600 Subject: [PATCH 8/8] cambiando dto --- backend/src/place/dto/get-place.dto.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/place/dto/get-place.dto.ts b/backend/src/place/dto/get-place.dto.ts index c42c6983..33dd5c6f 100644 --- a/backend/src/place/dto/get-place.dto.ts +++ b/backend/src/place/dto/get-place.dto.ts @@ -1,4 +1,5 @@ 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() -- GitLab