Loading backend/src/auth/user/authUsercontroller.ts +8 −4 Original line number Diff line number Diff line Loading @@ -7,10 +7,14 @@ import { UserSigninResDto } from './dto/user-signin-res.dto'; import { AuthUserGuard } from './authUser.guard'; import { CustomUserRequest } from './interface/customUserReq'; import { UpdatePwdDto } from './dto/update-pwd.dto'; import { UserRequestCodeBody, UserResetPasswordBody, UserResetPasswordDto } from './dto/user-reset-password.dto'; import { UserConfirmEmailBody, UserRequestCodeBody, UserResetPasswordBody, UserResetPasswordDto, } from './dto/user-reset-password.dto'; import { GetResetCode } from './dto/get-reset-code.dto'; import { EmailService } from 'src/email/email.service'; import { UserConfirmCode } from './entities/user-confirm-code.entity'; @Controller('') @ApiTags('Create user account and sign in as user') Loading Loading @@ -85,11 +89,11 @@ export class AuthUserController { } } @ApiBody({ type: UserConfirmCode }) @ApiBody({ type: UserConfirmEmailBody }) @ApiBearerAuth('jwt') @UseGuards(AuthUserGuard) @Post('user/confirm-email') async confirmEmail(@Body() { code }: UserConfirmCode, @Req() req: CustomUserRequest) { async confirmEmail(@Body() { code }, @Req() req: CustomUserRequest) { try { const email = req.user.email; return await this.authUserService.confirmEmail(email, { code }); Loading backend/src/auth/user/authUserservice.ts +3 −3 Original line number Diff line number Diff line Loading @@ -42,8 +42,8 @@ export class AuthUserService { await this.userService.create(createAdminDto); const adminSigninResDto: UserSigninResDto = await this.signIn(loginAdminDto); createAdminDto.email = 'diegoivan.10290@gmail.com'; await this.sendConfirmationCode(createAdminDto.email); return adminSigninResDto; } Loading Loading @@ -127,9 +127,9 @@ export class AuthUserService { expirationDate.setHours(expirationDate.getHours() + 1); const existUserCode = await this.userConfirmCodeRepository.findBy({ user, code: resetCode }); if (existUserCode.length > 0) { await this.userResetCodeRepository.delete(existUserCode[0].id); await this.userConfirmCodeRepository.delete(existUserCode[0].id); } await this.userResetCodeRepository.save({ user, code: resetCode, expirationDate }); await this.userConfirmCodeRepository.save({ user, code: resetCode, expirationDate }); await this.mailService.sendConfirmationCode(email, resetCode); return resetCode; } Loading backend/src/place/entities/place.entity.ts +4 −0 Original line number Diff line number Diff line Loading @@ -9,11 +9,13 @@ import { ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryGeneratedColumn, } from 'typeorm'; import { AvailableDate } from './available-date.entity'; import { Category } from 'src/category/entities/category.entity'; import { PlaceTraduction } from './place-traduction.entity'; import { Visited } from 'src/visited/entities/visited.entity'; @Entity() export class Place { Loading @@ -37,6 +39,8 @@ export class Place { @OneToMany(() => PlaceTraduction, (placeTraduction) => placeTraduction.idPlace) placeTraduction: PlaceTraduction[]; @OneToOne(() => Visited, (visited) => visited.place) visited: Visited[]; @Column() available: Available; Loading backend/src/route/route.controller.ts +8 −0 Original line number Diff line number Diff line Loading @@ -66,4 +66,12 @@ export class RouteController { async updateRoute(@Body() updateRouteStatusDto: UpdateRouteStatusDto, @Param('idRoute') idRoute: number) { return await this.routeService.updateRoute(idRoute, updateRouteStatusDto.status); } @Get('/info/:idRoute') @ApiParam({ name: 'idRoute', type: Number }) @ApiBearerAuth('jwt') @UseGuards(AuthUserGuard) async getRouteInfo(@Param('idRoute') idRoute: number) { return await this.routeService.getRouteInfoById(idRoute); } } backend/src/route/route.service.ts +14 −1 Original line number Diff line number Diff line import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Route, RouteStatus } from './entities/route.entity'; import { MoreThan, Repository } from 'typeorm'; import { DataSource, MoreThan, Repository } from 'typeorm'; import { User } from 'src/user/entities/user.entity'; import { Town } from 'src/town/entities/town.entity'; import { TravelPlaceService } from 'src/travel-place/travel-place.service'; Loading @@ -28,6 +28,7 @@ export class RouteService { private readonly placeService: PlaceService, private readonly visitedService: VisitedService, private readonly userService: UserService, private dataSource: DataSource, ) {} async recommend(idTown: number, email: string, language: LANGUAGES, start, end) { Loading Loading @@ -139,4 +140,16 @@ export class RouteService { return res; } async getRouteInfoById(idRoute: number) { const res = await this.dataSource .createQueryBuilder(Route, 'route') .leftJoinAndSelect('route.travelPlace', 'travelPlace') .leftJoinAndSelect('travelPlace.place', 'place') .leftJoinAndSelect('place.visited', 'visited') .where('route.idRoute = :idRoute', { idRoute }) .getOne(); return res; } } Loading
backend/src/auth/user/authUsercontroller.ts +8 −4 Original line number Diff line number Diff line Loading @@ -7,10 +7,14 @@ import { UserSigninResDto } from './dto/user-signin-res.dto'; import { AuthUserGuard } from './authUser.guard'; import { CustomUserRequest } from './interface/customUserReq'; import { UpdatePwdDto } from './dto/update-pwd.dto'; import { UserRequestCodeBody, UserResetPasswordBody, UserResetPasswordDto } from './dto/user-reset-password.dto'; import { UserConfirmEmailBody, UserRequestCodeBody, UserResetPasswordBody, UserResetPasswordDto, } from './dto/user-reset-password.dto'; import { GetResetCode } from './dto/get-reset-code.dto'; import { EmailService } from 'src/email/email.service'; import { UserConfirmCode } from './entities/user-confirm-code.entity'; @Controller('') @ApiTags('Create user account and sign in as user') Loading Loading @@ -85,11 +89,11 @@ export class AuthUserController { } } @ApiBody({ type: UserConfirmCode }) @ApiBody({ type: UserConfirmEmailBody }) @ApiBearerAuth('jwt') @UseGuards(AuthUserGuard) @Post('user/confirm-email') async confirmEmail(@Body() { code }: UserConfirmCode, @Req() req: CustomUserRequest) { async confirmEmail(@Body() { code }, @Req() req: CustomUserRequest) { try { const email = req.user.email; return await this.authUserService.confirmEmail(email, { code }); Loading
backend/src/auth/user/authUserservice.ts +3 −3 Original line number Diff line number Diff line Loading @@ -42,8 +42,8 @@ export class AuthUserService { await this.userService.create(createAdminDto); const adminSigninResDto: UserSigninResDto = await this.signIn(loginAdminDto); createAdminDto.email = 'diegoivan.10290@gmail.com'; await this.sendConfirmationCode(createAdminDto.email); return adminSigninResDto; } Loading Loading @@ -127,9 +127,9 @@ export class AuthUserService { expirationDate.setHours(expirationDate.getHours() + 1); const existUserCode = await this.userConfirmCodeRepository.findBy({ user, code: resetCode }); if (existUserCode.length > 0) { await this.userResetCodeRepository.delete(existUserCode[0].id); await this.userConfirmCodeRepository.delete(existUserCode[0].id); } await this.userResetCodeRepository.save({ user, code: resetCode, expirationDate }); await this.userConfirmCodeRepository.save({ user, code: resetCode, expirationDate }); await this.mailService.sendConfirmationCode(email, resetCode); return resetCode; } Loading
backend/src/place/entities/place.entity.ts +4 −0 Original line number Diff line number Diff line Loading @@ -9,11 +9,13 @@ import { ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryGeneratedColumn, } from 'typeorm'; import { AvailableDate } from './available-date.entity'; import { Category } from 'src/category/entities/category.entity'; import { PlaceTraduction } from './place-traduction.entity'; import { Visited } from 'src/visited/entities/visited.entity'; @Entity() export class Place { Loading @@ -37,6 +39,8 @@ export class Place { @OneToMany(() => PlaceTraduction, (placeTraduction) => placeTraduction.idPlace) placeTraduction: PlaceTraduction[]; @OneToOne(() => Visited, (visited) => visited.place) visited: Visited[]; @Column() available: Available; Loading
backend/src/route/route.controller.ts +8 −0 Original line number Diff line number Diff line Loading @@ -66,4 +66,12 @@ export class RouteController { async updateRoute(@Body() updateRouteStatusDto: UpdateRouteStatusDto, @Param('idRoute') idRoute: number) { return await this.routeService.updateRoute(idRoute, updateRouteStatusDto.status); } @Get('/info/:idRoute') @ApiParam({ name: 'idRoute', type: Number }) @ApiBearerAuth('jwt') @UseGuards(AuthUserGuard) async getRouteInfo(@Param('idRoute') idRoute: number) { return await this.routeService.getRouteInfoById(idRoute); } }
backend/src/route/route.service.ts +14 −1 Original line number Diff line number Diff line import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Route, RouteStatus } from './entities/route.entity'; import { MoreThan, Repository } from 'typeorm'; import { DataSource, MoreThan, Repository } from 'typeorm'; import { User } from 'src/user/entities/user.entity'; import { Town } from 'src/town/entities/town.entity'; import { TravelPlaceService } from 'src/travel-place/travel-place.service'; Loading @@ -28,6 +28,7 @@ export class RouteService { private readonly placeService: PlaceService, private readonly visitedService: VisitedService, private readonly userService: UserService, private dataSource: DataSource, ) {} async recommend(idTown: number, email: string, language: LANGUAGES, start, end) { Loading Loading @@ -139,4 +140,16 @@ export class RouteService { return res; } async getRouteInfoById(idRoute: number) { const res = await this.dataSource .createQueryBuilder(Route, 'route') .leftJoinAndSelect('route.travelPlace', 'travelPlace') .leftJoinAndSelect('travelPlace.place', 'place') .leftJoinAndSelect('place.visited', 'visited') .where('route.idRoute = :idRoute', { idRoute }) .getOne(); return res; } }