diff --git a/backend/src/place/place.controller.ts b/backend/src/place/place.controller.ts index b98b3ae8447043bd4718649dabc4f0298abc29ad..4af704793dae0195e75f9617ab00e0d0660995de 100644 --- a/backend/src/place/place.controller.ts +++ b/backend/src/place/place.controller.ts @@ -24,6 +24,8 @@ import { CustomAdminRequest } from 'src/auth/admin/interface/customAdminReq'; import { UpdatePlaceReqDto } from './dto/update-place.req.dto'; import { AuthAdminGuard } from 'src/auth/admin/authAdmin.guard'; import { GetPlaceDto } from './dto/get-place.dto'; +import { AuthUserGuard } from 'src/auth/user/authUser.guard'; +import { CustomUserRequest } from 'src/auth/user/interface/customUserReq'; @Controller('place') @ApiTags('Place') @@ -96,4 +98,13 @@ export class PlaceController { throw e; } } + + @Get('open/:idTown/:lang') + @ApiBearerAuth('jwt') + @ApiConsumes('json') + @UseGuards(AuthUserGuard) + @ApiParam({ name: 'idTown', type: Number }) + async findOpenPlaces(@Param('idTown') idTown: number, @Param('lang') lang: string, @Req() req: CustomUserRequest) { + return await this.placeService.findPlacesNotVisitedByUserAndOpenResponse(req.user.email, lang as LANGUAGES, idTown); + } } diff --git a/backend/src/place/place.module.ts b/backend/src/place/place.module.ts index 31f722214a648554fff4ed8f703ab3f75afb2449..2b6720f6a91ae596d310c6d7144bf3c8c67f1c30 100644 --- a/backend/src/place/place.module.ts +++ b/backend/src/place/place.module.ts @@ -16,6 +16,14 @@ import { JwtService } from '@nestjs/jwt'; import { EncryptionService } from 'src/auth/encryption/encryption.service'; import { Admin } from 'src/admin/entities/admin.entity'; import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity'; +import { AuthUserService } from 'src/auth/user/authUserservice'; +import { UserResetCode } from 'src/auth/user/entities/user-reset-code.entity'; +import { UserConfirmCode } from 'src/auth/user/entities/user-confirm-code.entity'; +import { UserService } from 'src/user/user.service'; +import { EmailService } from 'src/email/email.service'; +import { User } from 'src/user/entities/user.entity'; +import { CategoryService } from 'src/category/category.service'; +import { Category } from 'src/category/entities/category.entity'; @Module({ controllers: [PlaceController], @@ -28,6 +36,10 @@ import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity JwtService, EncryptionService, TownService, + AuthUserService, + UserService, + EmailService, + CategoryService, ], imports: [ TypeOrmModule.forFeature([ @@ -39,6 +51,10 @@ import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity State, Admin, AdminResetCode, + UserResetCode, + UserConfirmCode, + User, + Category, ]), TypeOrmModule, ], diff --git a/backend/src/place/place.service.ts b/backend/src/place/place.service.ts index 115604f7175fcb68604ecb2808e2ce9b1829285e..a480ddd3d4c0818c026184f0bac074bd5c599504 100644 --- a/backend/src/place/place.service.ts +++ b/backend/src/place/place.service.ts @@ -249,4 +249,25 @@ export class PlaceService { return placesWithAvailability.filter((place) => place !== null); } + + async findPlacesNotVisitedByUserAndOpenResponse(email: string, lang: LANGUAGES, idTown: number) { + const places: GetPlaceDto[] = await this.findPlacesNotVisitedByUserAndOpen(email, lang, idTown); + + const placesResponse = []; + for (const place of places) { + const visited: any = await this.dataSource + .getRepository(Visited) + .createQueryBuilder('visited') + .leftJoinAndSelect('visited.place', 'place') + .where('visited.user = :email', { email }) + .andWhere('place.idPlace = :idPlace', { idPlace: place.idPlace }) + .getOne(); + + placesResponse.push({ + ...place, + visited: visited ? true : false, + }); + } + return placesResponse; + } } diff --git a/backend/src/pointOfInterest/PointOfInterest.service.ts b/backend/src/pointOfInterest/PointOfInterest.service.ts index 8ec12a181d57561bee56aa60583c40f4491315bf..607e1100170a2f0ba14da19966e69ac912933205 100644 --- a/backend/src/pointOfInterest/PointOfInterest.service.ts +++ b/backend/src/pointOfInterest/PointOfInterest.service.ts @@ -48,11 +48,11 @@ export class PointOfInterestService { const insertedId = (await this.pointRepository.insert(createPointDto)).raw.insertId; const spanishAudio = await this.convertTextToSpeech( - `${createPointAndTradDto.contentES}\n${createPointAndTradDto.directionsES}`, + `${createPointAndTradDto.contentES}\n${createPointAndTradDto.directionsES || ''}`, LANGUAGES.ES, ); const englishAudio = await this.convertTextToSpeech( - `${createPointAndTradDto.contentEN}\n${createPointAndTradDto.directionsEN}`, + `${createPointAndTradDto.contentEN}\n${createPointAndTradDto.directionsEN || ''}`, LANGUAGES.EN, );