From c8c095c0d548656377b6bf598862e03527ef33ed Mon Sep 17 00:00:00 2001 From: Patrick Otero Date: Wed, 6 Sep 2023 23:07:11 -0300 Subject: [PATCH] cleaning - user controller cleaning --- src/modules/mails/mail.module.ts | 3 + .../user/decorators/match.decorator.ts | 28 +++ src/modules/user/dtos/create-user.dto.ts | 7 +- .../user/dtos/update-my-password.dto.ts | 4 +- .../user/services/create-user.service.ts | 2 +- .../user/services/delete-user.service.ts | 5 +- .../user/services/find-one-user.service.ts | 16 +- src/modules/user/user.controller.ts | 224 ++---------------- .../user/create-user.swagger.decorator.ts | 22 ++ .../user/delete-user.swagger.decorator.ts | 33 +++ .../user/get-user-adm.swagger.decorator.ts | 34 +++ .../user/get-user.swagger.decorator.ts | 29 +++ .../recover-by-email.swagger.decorator.ts | 28 +++ ...-after-email-recovery.swagger.decorator.ts | 28 +++ .../user/update-password.swagger.decorator.ts | 28 +++ .../user/update-user.swagger.decorator.ts | 39 +++ .../user/view-users.swagger.decorator.ts | 28 +++ 17 files changed, 341 insertions(+), 217 deletions(-) create mode 100644 src/modules/user/decorators/match.decorator.ts create mode 100644 src/shared/Swagger/decorators/user/create-user.swagger.decorator.ts create mode 100644 src/shared/Swagger/decorators/user/delete-user.swagger.decorator.ts create mode 100644 src/shared/Swagger/decorators/user/get-user-adm.swagger.decorator.ts create mode 100644 src/shared/Swagger/decorators/user/get-user.swagger.decorator.ts create mode 100644 src/shared/Swagger/decorators/user/recover-by-email.swagger.decorator.ts create mode 100644 src/shared/Swagger/decorators/user/update-pass-after-email-recovery.swagger.decorator.ts create mode 100644 src/shared/Swagger/decorators/user/update-password.swagger.decorator.ts create mode 100644 src/shared/Swagger/decorators/user/update-user.swagger.decorator.ts create mode 100644 src/shared/Swagger/decorators/user/view-users.swagger.decorator.ts diff --git a/src/modules/mails/mail.module.ts b/src/modules/mails/mail.module.ts index a8c9c7d..6cf6f38 100644 --- a/src/modules/mails/mail.module.ts +++ b/src/modules/mails/mail.module.ts @@ -18,6 +18,9 @@ import { MailService } from './mail.service'; user: config.get('MAIL_USER'), pass: config.get('MAIL_PASSWORD'), }, + tls: { + rejectUnauthorized: false + } }, defaults: { from: `no-reply `, diff --git a/src/modules/user/decorators/match.decorator.ts b/src/modules/user/decorators/match.decorator.ts new file mode 100644 index 0000000..576a995 --- /dev/null +++ b/src/modules/user/decorators/match.decorator.ts @@ -0,0 +1,28 @@ +import { + registerDecorator, + ValidationArguments, + ValidationOptions, + ValidatorConstraint, + ValidatorConstraintInterface, + } from 'class-validator'; + + export function Match(property: string, validationOptions?: ValidationOptions) { + return (object: any, propertyName: string) => { + registerDecorator({ + target: object.constructor, + propertyName, + options: validationOptions, + constraints: [property], + validator: MatchConstraint, + }); + }; + } + + @ValidatorConstraint({ name: 'Match' }) + export class MatchConstraint implements ValidatorConstraintInterface { + validate(value: any, args: ValidationArguments) { + const [relatedPropertyName] = args.constraints; + const relatedValue = (args.object as any)[relatedPropertyName]; + return value === relatedValue; + } + } \ No newline at end of file diff --git a/src/modules/user/dtos/create-user.dto.ts b/src/modules/user/dtos/create-user.dto.ts index a24a825..f6eae04 100644 --- a/src/modules/user/dtos/create-user.dto.ts +++ b/src/modules/user/dtos/create-user.dto.ts @@ -11,6 +11,7 @@ import { Validate, } from 'class-validator'; import { UserRole } from '../../../shared/utils/userRole/userRole'; +import { Match } from '../decorators/match.decorator'; export class CreateUserDto { @IsNotEmpty() @@ -33,7 +34,6 @@ export class CreateUserDto { @IsNotEmpty() @IsString() - @Length(8, 20) @Matches( /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()\-_=+{};:,<.>])[a-zA-Z\d!@#$%^&*()\-_=+{};:,<.>.]{8,}$/, { @@ -49,13 +49,12 @@ export class CreateUserDto { @IsNotEmpty() @IsString() - @Length(8, 20) @ApiProperty({ description: 'Confirmação de senha', example: 'Abcd@1234', }) - @Validate((value, { object }) => value === object.password, { - message: 'Senhas precisam ser idênticas', + @Match('password', { + message: 'The password does not match with the password confirmation', }) confirmPassword: string; diff --git a/src/modules/user/dtos/update-my-password.dto.ts b/src/modules/user/dtos/update-my-password.dto.ts index fc30e58..39f041b 100644 --- a/src/modules/user/dtos/update-my-password.dto.ts +++ b/src/modules/user/dtos/update-my-password.dto.ts @@ -40,7 +40,7 @@ export class CreatePasswordHashDto { message: 'Senha muito fraca', }) @ApiProperty({ - description: 'Inserir senha com os critérios informados', + description: 'A senha precisa ter no mínimo 8 caracteres, máximo de 50, uma letra maiúscula, um número e um símbolo.', example: 'Abcd@1234', }) password: string; @@ -48,7 +48,7 @@ export class CreatePasswordHashDto { @IsString() @Length(8, 50) @Matches(/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/, { - message: 'Inserir senha com os critérios informados', + message: 'A senha precisa ter no mínimo 8 caracteres, máximo de 50, uma letra maiúscula, um número e um símbolo.', }) @ApiProperty({ description: 'Confirmação de senha de Login', diff --git a/src/modules/user/services/create-user.service.ts b/src/modules/user/services/create-user.service.ts index 26251ba..27fcdf5 100644 --- a/src/modules/user/services/create-user.service.ts +++ b/src/modules/user/services/create-user.service.ts @@ -22,7 +22,7 @@ export class CreateUserService { if (userAlreadyExists) { return { - status: 404, + status: 400, data: { message: 'E-mail já cadastrado.', }, diff --git a/src/modules/user/services/delete-user.service.ts b/src/modules/user/services/delete-user.service.ts index 2087701..53ee040 100644 --- a/src/modules/user/services/delete-user.service.ts +++ b/src/modules/user/services/delete-user.service.ts @@ -1,13 +1,12 @@ import { Injectable } from '@nestjs/common'; -import { UsersEntity } from '../../../database/entities/users.entity'; import { UserRepository } from '../repository/user.repository'; @Injectable() export class DeleteUserService { constructor(private userRepository: UserRepository) {} - async execute(user: UsersEntity) { - await this.userRepository.deleteUserById(user.id); + async execute(id: string) { + await this.userRepository.deleteUserById(id); return { message: 'User deleted successfully' }; } diff --git a/src/modules/user/services/find-one-user.service.ts b/src/modules/user/services/find-one-user.service.ts index cdf5884..6d4c3b1 100644 --- a/src/modules/user/services/find-one-user.service.ts +++ b/src/modules/user/services/find-one-user.service.ts @@ -1,17 +1,19 @@ import { Injectable } from '@nestjs/common'; -import { UsersEntity } from '../../../database/entities/users.entity'; import { UserRepository } from '../repository/user.repository'; @Injectable() export class FindOneUserService { constructor(public userRepository: UserRepository) {} - async execute(user: UsersEntity) { - delete user.password; - delete user.type; - delete user.ip; - delete user.recoverPasswordToken; + async execute(id: string) { - return user; + const userExists = await this.userRepository.findOneById(id) + + delete userExists.password; + delete userExists.type; + delete userExists.ip; + delete userExists.recoverPasswordToken; + + return userExists; } } diff --git a/src/modules/user/user.controller.ts b/src/modules/user/user.controller.ts index a1b5b06..deba496 100644 --- a/src/modules/user/user.controller.ts +++ b/src/modules/user/user.controller.ts @@ -3,7 +3,6 @@ import { Controller, Delete, Get, - HttpStatus, Param, Patch, Post, @@ -18,16 +17,10 @@ import { import { AuthGuard } from '@nestjs/passport'; import { ApiBearerAuth, - ApiBody, - ApiOperation, - ApiParam, - ApiResponse, ApiTags, } from '@nestjs/swagger'; import { Request, Response } from 'express'; import { UsersEntity } from '../../database/entities/users.entity'; -import { BadRequestSwagger } from '../../shared/Swagger/bad-request.swagger'; -import { UnauthorizedSwagger } from '../../shared/Swagger/unauthorized.swagger'; import { PageOptionsDto } from '../../shared/pagination'; import { LoggedAdmin } from '../auth/decorator/logged-admin.decorator'; import { LoggedUser } from '../auth/decorator/logged-user.decorator'; @@ -39,13 +32,8 @@ import { } from './dtos/update-my-password.dto'; import { UpdateUserDto } from './dtos/update-user.dto'; -import { FileInterceptor } from '@nestjs/platform-express'; -import { NotFoundSwagger } from '../../shared/Swagger/not-found.swagger'; -import { UnprocessableEntitySwagger } from '../../shared/Swagger/unprocessable-entity.swagger'; -import { CreateResponseSwagger } from '../../shared/Swagger/user/create-response.swagger'; -import { ListResponseSwagger } from '../../shared/Swagger/user/list-response.swagger'; -import { RecoveryPasswordSwagger } from '../../shared/Swagger/user/recovery-password.swagger'; -import { GetByParamsDto } from './dtos/get-by-params.dto'; +import { FileInterceptor } from "@nestjs/platform-express"; + import { CreateUserService, DeleteUserService, @@ -57,6 +45,15 @@ import { } from './services'; import { ActivateUserService } from './services/activate-user.service'; import { UpdatePasswordService } from './services/update-password.service'; +import { SwaggerCreateUser } from 'src/shared/Swagger/decorators/user/create-user.swagger.decorator'; +import { SwaggerGetUser } from 'src/shared/Swagger/decorators/user/get-user.swagger.decorator'; +import { SwaggerFindUsers } from 'src/shared/Swagger/decorators/user/view-users.swagger.decorator'; +import { SwaggerGetUserAdm } from 'src/shared/Swagger/decorators/user/get-user-adm.swagger.decorator'; +import { SwaggerUpdateUser } from 'src/shared/Swagger/decorators/user/update-user.swagger.decorator'; +import { SwaggerDeleteUser } from 'src/shared/Swagger/decorators/user/delete-user.swagger.decorator'; +import { SwaggerRecoverEmail } from 'src/shared/Swagger/decorators/user/recover-by-email.swagger.decorator'; +import { SwaggerUpdatePassAfterRecovery } from 'src/shared/Swagger/decorators/user/update-pass-after-email-recovery.swagger.decorator'; +import { SwaggerUpdatePassword } from 'src/shared/Swagger/decorators/user/update-password.swagger.decorator'; @ApiTags('User') @Controller('user') @@ -74,24 +71,7 @@ export class UserController { ) {} @Post() - @ApiResponse({ - status: HttpStatus.CREATED, - description: 'Exemplo do retorno de sucesso da rota', - type: CreateResponseSwagger, - }) - @ApiResponse({ - status: HttpStatus.UNAUTHORIZED, - description: 'Modelo de erro', - type: UnauthorizedSwagger, - }) - @ApiResponse({ - status: HttpStatus.BAD_REQUEST, - description: 'Modelo de erro', - type: BadRequestSwagger, - }) - @ApiOperation({ - summary: 'Criar um usuário!', - }) + @SwaggerCreateUser() async createNewUser( @Body() createUser: CreateUserDto, @Res() res: Response, @@ -106,47 +86,13 @@ export class UserController { } @Put('activate/:id') - @ApiResponse({ - status: HttpStatus.OK, - description: 'Exemplo do retorno de sucesso da rota', - type: CreateResponseSwagger, - }) - @ApiResponse({ - status: HttpStatus.UNPROCESSABLE_ENTITY, - description: 'Modelo de erro', - type: UnprocessableEntitySwagger, - }) - @ApiResponse({ - status: HttpStatus.BAD_REQUEST, - description: 'Modelo de erro', - type: BadRequestSwagger, - }) - @ApiOperation({ - summary: 'Ativar um usuário pelo ID', - }) + @SwaggerGetUser() async activateUser(@Param('id') id: string) { return this.activateUserService.execute(id); } @Get() - @ApiResponse({ - status: HttpStatus.OK, - description: 'Exemplo do retorno de sucesso da rota', - type: ListResponseSwagger, - }) - @ApiResponse({ - status: HttpStatus.UNAUTHORIZED, - description: 'Modelo de erro', - type: UnauthorizedSwagger, - }) - @ApiResponse({ - status: HttpStatus.BAD_REQUEST, - description: 'Modelo de erro', - type: BadRequestSwagger, - }) - @ApiOperation({ - summary: 'Visualizar todos os usuários', - }) + @SwaggerFindUsers() @UseGuards(AuthGuard()) @ApiBearerAuth() async getAllUsers( @@ -157,68 +103,18 @@ export class UserController { } @Get(':id') - @ApiResponse({ - status: HttpStatus.OK, - description: 'Exemplo do retorno de sucesso da rota', - type: CreateResponseSwagger, - }) - @ApiResponse({ - status: HttpStatus.UNAUTHORIZED, - description: 'Modelo de erro', - type: UnauthorizedSwagger, - }) - @ApiResponse({ - status: HttpStatus.BAD_REQUEST, - description: 'Modelo de erro', - type: BadRequestSwagger, - }) - @ApiOperation({ - summary: 'Visualizar um usuário pelo ID (precisa ser adm)', - }) - @ApiParam({ - type: GetByParamsDto, - name: '', - }) + @SwaggerGetUserAdm() @UseGuards(AuthGuard()) @ApiBearerAuth() - async getOneUser(@LoggedUser() user: UsersEntity) { - return this.findOneUserService.execute(user); + async getOneUser(@Param("id") id: string, @LoggedUser() user: UsersEntity) { + return this.findOneUserService.execute(id); } @Put() @ApiBearerAuth() @UseGuards(AuthGuard()) @UseInterceptors(FileInterceptor('file')) - @ApiBody({ - description: 'Upload images', - schema: { - type: 'object', - properties: { - file: { - type: 'string', - format: 'binary', - }, - }, - }, - }) - @ApiResponse({ - status: HttpStatus.OK, - description: 'Exemplo do retorno de sucesso da rota', - type: BadRequestSwagger, - }) - @ApiResponse({ - status: HttpStatus.UNAUTHORIZED, - description: 'Modelo de erro', - type: UnauthorizedSwagger, - }) - @ApiResponse({ - status: HttpStatus.BAD_REQUEST, - description: 'Modelo de erro', - type: BadRequestSwagger, - }) - @ApiOperation({ - summary: 'Atualizar um usuário pelo ID', - }) + @SwaggerUpdateUser() async updateUser( @LoggedUser() user: UsersEntity, @Body() data: UpdateUserDto, @@ -228,53 +124,15 @@ export class UserController { } @Delete(':id') - @ApiResponse({ - status: HttpStatus.OK, - description: 'Exemplo do retorno de sucesso da rota', - type: NotFoundSwagger, - }) - @ApiResponse({ - status: HttpStatus.UNAUTHORIZED, - description: 'Modelo de erro', - type: UnauthorizedSwagger, - }) - @ApiResponse({ - status: HttpStatus.BAD_REQUEST, - description: 'Modelo de erro', - type: BadRequestSwagger, - }) - @ApiOperation({ - summary: 'Deletar um usuário pelo ID', - }) - @ApiParam({ - type: GetByParamsDto, - name: '', - }) + @SwaggerDeleteUser() @UseGuards(AuthGuard()) @ApiBearerAuth() - async deleteUser(@LoggedUser() user: UsersEntity) { - return this.deleteUserService.execute(user); + async deleteUser(@Param("id") id: string, @LoggedUser() user: UsersEntity) { + return this.deleteUserService.execute(id); } @Patch('recovery_password') - @ApiResponse({ - status: HttpStatus.OK, - description: 'Exemplo do retorno de sucesso da rota', - type: RecoveryPasswordSwagger, - }) - @ApiResponse({ - status: HttpStatus.UNAUTHORIZED, - description: 'Modelo de erro', - type: UnauthorizedSwagger, - }) - @ApiResponse({ - status: HttpStatus.BAD_REQUEST, - description: 'Modelo de erro', - type: BadRequestSwagger, - }) - @ApiOperation({ - summary: 'Send email to recovery password.', - }) + @SwaggerRecoverEmail() async recoveryPasswordSendEmail( @Body() { email }: EmailDto, @Res() res: Response, @@ -285,24 +143,7 @@ export class UserController { } @Patch('update_password_email') - @ApiResponse({ - status: HttpStatus.OK, - description: 'Exemplo do retorno de sucesso da rota', - type: NotFoundSwagger, - }) - @ApiResponse({ - status: HttpStatus.UNAUTHORIZED, - description: 'Modelo de erro', - type: UnauthorizedSwagger, - }) - @ApiResponse({ - status: HttpStatus.BAD_REQUEST, - description: 'Modelo de erro', - type: BadRequestSwagger, - }) - @ApiOperation({ - summary: 'User update password.', - }) + @SwaggerUpdatePassAfterRecovery() async updatePasswordAfterEmail( @Body() updatePassword: CreatePasswordHashDto, @Res() res: Response, @@ -316,24 +157,7 @@ export class UserController { @Patch('update_password') @UseGuards(AuthGuard()) @ApiBearerAuth() - @ApiResponse({ - status: HttpStatus.OK, - description: 'Exemplo do retorno de sucesso da rota', - type: NotFoundSwagger, - }) - @ApiResponse({ - status: HttpStatus.UNAUTHORIZED, - description: 'Modelo de erro', - type: UnauthorizedSwagger, - }) - @ApiResponse({ - status: HttpStatus.BAD_REQUEST, - description: 'Modelo de erro', - type: BadRequestSwagger, - }) - @ApiOperation({ - summary: 'User update password without recovery e-mail.', - }) + @SwaggerUpdatePassword() async updatePassword( @LoggedUser() user: UsersEntity, @Body() passData: UpdateMyPasswordDto, diff --git a/src/shared/Swagger/decorators/user/create-user.swagger.decorator.ts b/src/shared/Swagger/decorators/user/create-user.swagger.decorator.ts new file mode 100644 index 0000000..0e59806 --- /dev/null +++ b/src/shared/Swagger/decorators/user/create-user.swagger.decorator.ts @@ -0,0 +1,22 @@ +import { applyDecorators, HttpStatus } from '@nestjs/common'; +import { ApiOperation, ApiResponse } from '@nestjs/swagger'; +import { BadRequestSwagger } from '../../bad-request.swagger'; +import { NotFoundSwagger } from '../../not-found.swagger'; + +export function SwaggerCreateUser() { + return applyDecorators( + ApiResponse({ + status: HttpStatus.CREATED, + description: 'Exemplo do retorno de sucesso da rota', + type: NotFoundSwagger, + }), + ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Modelo de erro', + type: BadRequestSwagger, + }), + ApiOperation({ + summary: 'Rota para cadastrar usuário plataforma', + }), + ); +} diff --git a/src/shared/Swagger/decorators/user/delete-user.swagger.decorator.ts b/src/shared/Swagger/decorators/user/delete-user.swagger.decorator.ts new file mode 100644 index 0000000..10d1091 --- /dev/null +++ b/src/shared/Swagger/decorators/user/delete-user.swagger.decorator.ts @@ -0,0 +1,33 @@ +import { applyDecorators, HttpStatus } from '@nestjs/common'; +import { ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger'; +import { GetByParamsDto } from 'src/modules/user/dtos/get-by-params.dto'; +import { BadRequestSwagger } from '../../bad-request.swagger'; +import { NotFoundSwagger } from '../../not-found.swagger'; +import { UnauthorizedSwagger } from '../../unauthorized.swagger'; + +export function SwaggerDeleteUser() { + return applyDecorators( + ApiResponse({ + status: HttpStatus.OK, + description: 'Exemplo do retorno de sucesso da rota', + type: NotFoundSwagger, + }), + ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: 'Modelo de erro', + type: UnauthorizedSwagger, + }), + ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Modelo de erro', + type: BadRequestSwagger, + }), + ApiOperation({ + summary: 'Deletar um usuário pelo ID', + }), + ApiParam({ + type: GetByParamsDto, + name: '', + }) + ) +} \ No newline at end of file diff --git a/src/shared/Swagger/decorators/user/get-user-adm.swagger.decorator.ts b/src/shared/Swagger/decorators/user/get-user-adm.swagger.decorator.ts new file mode 100644 index 0000000..d7aff71 --- /dev/null +++ b/src/shared/Swagger/decorators/user/get-user-adm.swagger.decorator.ts @@ -0,0 +1,34 @@ +import { applyDecorators, HttpStatus } from '@nestjs/common'; +import { ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger'; +import { GetByParamsDto } from 'src/modules/user/dtos/get-by-params.dto'; +import { BadRequestSwagger } from '../../bad-request.swagger'; +import { UnauthorizedSwagger } from '../../unauthorized.swagger'; +import { CreateResponseSwagger } from '../../user/create-response.swagger'; + + +export function SwaggerGetUserAdm() { + return applyDecorators( + ApiResponse({ + status: HttpStatus.OK, + description: 'Exemplo do retorno de sucesso da rota', + type: CreateResponseSwagger, + }), + ApiResponse({ + status: HttpStatus.UNPROCESSABLE_ENTITY, + description: 'Modelo de erro', + type: UnauthorizedSwagger, + }), + ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Modelo de erro', + type: BadRequestSwagger, + }), + ApiOperation({ + summary: 'Visualizar um usuário pelo ID (precisa ser adm)', + }), + ApiParam({ + type: GetByParamsDto, + name: '', + }) + ); +} diff --git a/src/shared/Swagger/decorators/user/get-user.swagger.decorator.ts b/src/shared/Swagger/decorators/user/get-user.swagger.decorator.ts new file mode 100644 index 0000000..67d43d3 --- /dev/null +++ b/src/shared/Swagger/decorators/user/get-user.swagger.decorator.ts @@ -0,0 +1,29 @@ +import { applyDecorators, HttpStatus } from '@nestjs/common'; +import { ApiOperation, ApiResponse } from '@nestjs/swagger'; +import { BadRequestSwagger } from '../../bad-request.swagger'; +import { UnprocessableEntitySwagger } from '../../unprocessable-entity.swagger'; +import { CreateResponseSwagger } from '../../user/create-response.swagger'; + + +export function SwaggerGetUser() { + return applyDecorators( + ApiResponse({ + status: HttpStatus.OK, + description: 'Exemplo do retorno de sucesso da rota', + type: CreateResponseSwagger, + }), + ApiResponse({ + status: HttpStatus.UNPROCESSABLE_ENTITY, + description: 'Modelo de erro', + type: UnprocessableEntitySwagger, + }), + ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Modelo de erro', + type: BadRequestSwagger, + }), + ApiOperation({ + summary: 'Ativar um usuário pelo ID', + }) + ); +} diff --git a/src/shared/Swagger/decorators/user/recover-by-email.swagger.decorator.ts b/src/shared/Swagger/decorators/user/recover-by-email.swagger.decorator.ts new file mode 100644 index 0000000..7dcd96b --- /dev/null +++ b/src/shared/Swagger/decorators/user/recover-by-email.swagger.decorator.ts @@ -0,0 +1,28 @@ +import { applyDecorators, HttpStatus } from '@nestjs/common'; +import { ApiOperation, ApiResponse } from '@nestjs/swagger'; +import { BadRequestSwagger } from '../../bad-request.swagger'; +import { UnauthorizedSwagger } from '../../unauthorized.swagger'; +import { RecoveryPasswordSwagger } from '../../user/recovery-password.swagger'; + +export function SwaggerRecoverEmail() { + return applyDecorators( + ApiResponse({ + status: HttpStatus.OK, + description: 'Exemplo do retorno de sucesso da rota', + type: RecoveryPasswordSwagger, + }), + ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: 'Modelo de erro', + type: UnauthorizedSwagger, + }), + ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Modelo de erro', + type: BadRequestSwagger, + }), + ApiOperation({ + summary: 'Send email to recovery password.', + }), + ) +} \ No newline at end of file diff --git a/src/shared/Swagger/decorators/user/update-pass-after-email-recovery.swagger.decorator.ts b/src/shared/Swagger/decorators/user/update-pass-after-email-recovery.swagger.decorator.ts new file mode 100644 index 0000000..4ad0a49 --- /dev/null +++ b/src/shared/Swagger/decorators/user/update-pass-after-email-recovery.swagger.decorator.ts @@ -0,0 +1,28 @@ +import { applyDecorators, HttpStatus } from '@nestjs/common'; +import { ApiOperation, ApiResponse } from '@nestjs/swagger'; +import { BadRequestSwagger } from '../../bad-request.swagger'; +import { NotFoundSwagger } from '../../not-found.swagger'; +import { UnauthorizedSwagger } from '../../unauthorized.swagger'; + +export function SwaggerUpdatePassAfterRecovery() { + return applyDecorators( + ApiResponse({ + status: HttpStatus.OK, + description: 'Exemplo do retorno de sucesso da rota', + type: NotFoundSwagger, + }), + ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: 'Modelo de erro', + type: UnauthorizedSwagger, + }), + ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Modelo de erro', + type: BadRequestSwagger, + }), + ApiOperation({ + summary: 'User update password.', + }), + ) +} \ No newline at end of file diff --git a/src/shared/Swagger/decorators/user/update-password.swagger.decorator.ts b/src/shared/Swagger/decorators/user/update-password.swagger.decorator.ts new file mode 100644 index 0000000..0dfc189 --- /dev/null +++ b/src/shared/Swagger/decorators/user/update-password.swagger.decorator.ts @@ -0,0 +1,28 @@ +import { applyDecorators, HttpStatus } from '@nestjs/common'; +import { ApiOperation, ApiResponse } from '@nestjs/swagger'; +import { BadRequestSwagger } from '../../bad-request.swagger'; +import { NotFoundSwagger } from '../../not-found.swagger'; +import { UnauthorizedSwagger } from '../../unauthorized.swagger'; + +export function SwaggerUpdatePassword() { + return applyDecorators( + ApiResponse({ + status: HttpStatus.OK, + description: 'Exemplo do retorno de sucesso da rota', + type: NotFoundSwagger, + }), + ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: 'Modelo de erro', + type: UnauthorizedSwagger, + }), + ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Modelo de erro', + type: BadRequestSwagger, + }), + ApiOperation({ + summary: 'User update password without recovery e-mail.', + }) + ) +} \ No newline at end of file diff --git a/src/shared/Swagger/decorators/user/update-user.swagger.decorator.ts b/src/shared/Swagger/decorators/user/update-user.swagger.decorator.ts new file mode 100644 index 0000000..809103f --- /dev/null +++ b/src/shared/Swagger/decorators/user/update-user.swagger.decorator.ts @@ -0,0 +1,39 @@ +import { applyDecorators, HttpStatus } from "@nestjs/common" +import { ApiOperation, ApiResponse, ApiBody } from '@nestjs/swagger'; +import { BadRequestSwagger } from "../../bad-request.swagger"; +import { UnauthorizedSwagger } from "../../unauthorized.swagger"; + +export function SwaggerUpdateUser() { + return applyDecorators( + ApiBody({ + description: 'Upload images', + schema: { + type: 'object', + properties: { + file: { + type: 'string', + format: 'binary', + }, + }, + }, + }), + ApiResponse({ + status: HttpStatus.OK, + description: 'Exemplo do retorno de sucesso da rota', + type: BadRequestSwagger, + }), + ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: 'Modelo de erro', + type: UnauthorizedSwagger, + }), + ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Modelo de erro', + type: BadRequestSwagger, + }), + ApiOperation({ + summary: 'Atualizar um usuário pelo ID', + }) + ) +} \ No newline at end of file diff --git a/src/shared/Swagger/decorators/user/view-users.swagger.decorator.ts b/src/shared/Swagger/decorators/user/view-users.swagger.decorator.ts new file mode 100644 index 0000000..26a67f8 --- /dev/null +++ b/src/shared/Swagger/decorators/user/view-users.swagger.decorator.ts @@ -0,0 +1,28 @@ +import { applyDecorators, HttpStatus } from '@nestjs/common'; +import { ApiOperation, ApiResponse } from '@nestjs/swagger'; +import { BadRequestSwagger } from '../../bad-request.swagger'; +import { UnauthorizedSwagger } from '../../unauthorized.swagger'; +import { ListResponseSwagger } from '../../user/list-response.swagger'; + +export function SwaggerFindUsers() { + return applyDecorators( +ApiResponse({ + status: HttpStatus.OK, + description: 'Exemplo do retorno de sucesso da rota', + type: ListResponseSwagger, + }), + ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: 'Modelo de erro', + type: UnauthorizedSwagger, + }), + ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Modelo de erro', + type: BadRequestSwagger, + }), + ApiOperation({ + summary: 'Visualizar todos os usuários', + }), + ) +} \ No newline at end of file