From c194e7d252ccd8348e8fbe8b12f231b9ab1e65ce Mon Sep 17 00:00:00 2001 From: xXpuma99Xx <51341582+xXpuma99Xx@users.noreply.github.com> Date: Mon, 30 May 2022 19:48:04 -0500 Subject: [PATCH] =?UTF-8?q?usuario=20documentaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...o-escolares.dto.ts => usuario-dgae.dto.ts} | 5 +- src/usuario/dto/usuario-dgp.dto.ts | 9 ++ src/usuario/dto/usuario-registrar.dto.ts | 6 +- src/usuario/dto/usuario-update.dto.ts | 12 ++- src/usuario/usuario.controller.ts | 97 ++++++++++++++++++- 5 files changed, 121 insertions(+), 8 deletions(-) rename src/usuario/dto/{usuario-escolares.dto.ts => usuario-dgae.dto.ts} (51%) create mode 100644 src/usuario/dto/usuario-dgp.dto.ts diff --git a/src/usuario/dto/usuario-escolares.dto.ts b/src/usuario/dto/usuario-dgae.dto.ts similarity index 51% rename from src/usuario/dto/usuario-escolares.dto.ts rename to src/usuario/dto/usuario-dgae.dto.ts index 3d80972..8d2decd 100644 --- a/src/usuario/dto/usuario-escolares.dto.ts +++ b/src/usuario/dto/usuario-dgae.dto.ts @@ -1,6 +1,9 @@ import { IsNumberString } from 'class-validator'; -export class UsuarioEscolaresDto { +export class UsuarioDgaeDto { @IsNumberString() usuario: string; + + @IsNumberString() + id_institucion_carrera: string; } diff --git a/src/usuario/dto/usuario-dgp.dto.ts b/src/usuario/dto/usuario-dgp.dto.ts new file mode 100644 index 0000000..75dcce7 --- /dev/null +++ b/src/usuario/dto/usuario-dgp.dto.ts @@ -0,0 +1,9 @@ +import { IsNumberString, IsString } from 'class-validator'; + +export class UsuarioDgpDto { + @IsString() + rfc: string; + + @IsNumberString() + usuario: string; +} diff --git a/src/usuario/dto/usuario-registrar.dto.ts b/src/usuario/dto/usuario-registrar.dto.ts index 78a6f23..52eee7c 100644 --- a/src/usuario/dto/usuario-registrar.dto.ts +++ b/src/usuario/dto/usuario-registrar.dto.ts @@ -1,4 +1,4 @@ -import { IsInt, IsPhoneNumber } from 'class-validator'; +import { IsEmail, IsInt, IsOptional, IsPhoneNumber } from 'class-validator'; export class UsuarioRegistrarDto { @IsInt() @@ -6,4 +6,8 @@ export class UsuarioRegistrarDto { @IsPhoneNumber('MX') telefono: string; + + @IsEmail() + @IsOptional() + correo?: string; } diff --git a/src/usuario/dto/usuario-update.dto.ts b/src/usuario/dto/usuario-update.dto.ts index e037b62..0932820 100644 --- a/src/usuario/dto/usuario-update.dto.ts +++ b/src/usuario/dto/usuario-update.dto.ts @@ -1,4 +1,10 @@ -import { IsBoolean, IsInt, IsOptional, IsPhoneNumber } from 'class-validator'; +import { + IsBoolean, + IsEmail, + IsInt, + IsOptional, + IsPhoneNumber, +} from 'class-validator'; export class UsuarioUpdateDto { @IsInt() @@ -15,4 +21,8 @@ export class UsuarioUpdateDto { @IsPhoneNumber('MX') @IsOptional() telefono?: string; + + @IsEmail() + @IsOptional() + correo?: string; } diff --git a/src/usuario/usuario.controller.ts b/src/usuario/usuario.controller.ts index e395ad1..f1e7923 100644 --- a/src/usuario/usuario.controller.ts +++ b/src/usuario/usuario.controller.ts @@ -8,50 +8,137 @@ import { UseGuards, } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; -import { ApiTags } from '@nestjs/swagger'; +import { ApiBody, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger'; import { UsuarioService } from './usuario.service'; -import { UsuarioEscolaresDto } from './dto/usuario-escolares.dto'; +import { UsuarioDgaeDto } from './dto/usuario-dgae.dto'; +import { UsuarioDgpDto } from './dto/usuario-dgp.dto'; import { UsuarioRegistrarDto } from './dto/usuario-registrar.dto'; import { UsuarioUpdateDto } from './dto/usuario-update.dto'; import { UsuarioUsuariosDto } from './dto/usuario-usuarios.dto'; import { UsuarioDto } from './dto/usuario.dto'; @Controller('usuario') -// @ApiTags('usuario') +@ApiTags('usuario') export class UsuarioController { constructor(private usuarioService: UsuarioService) {} /* Pendiente por conexión */ - // @Get('dgae-dgp') - // dgaeDgp(@Query() query: UsuarioEscolaresDto) { + // @Get('dgae') + // dgae(@Query() query: UsuarioDgaeDto) { + // return this.usuarioService.dgaeDgp(query.usuario); + // } + // @Get('dgp') + // dgp(@Query() query: UsuarioDgpDto) { // return this.usuarioService.dgaeDgp(query.usuario); // } @Post('registrar') + @ApiOperation({ + description: 'Enpoint que realiza el registro de un usuario.', + }) + @ApiBody({ + description: + 'Todas la variables a excepción de id_usuario son obligatorias.', + examples: { + ejemplo: { value: { id_usuario: 1, telefono: '', correo: '' } }, + }, + }) registrar(@Body() body: UsuarioRegistrarDto) { return this.usuarioService.registrar(body.id_usuario, body.telefono); } @Put() // @UseGuards(AuthGuard('jwt')) + @ApiOperation({ + description: 'Enpoint que actualiza la información de un usuario.', + }) + @ApiBody({ + description: + 'Todas las variables a excepción de id_usuario son opcionales.', + examples: { + ejemplo: { + value: { + id_usuario: 1, + activo: true, + multa: false, + telefono: '', + correo: '', + }, + }, + }, + }) update(@Body() body: UsuarioUpdateDto) { return this.usuarioService.update(body); } @Put('update-password') // @UseGuards(AuthGuard('jwt')) + @ApiOperation({ + description: 'Enpoint que envía una nueva password al correo del usuario.', + }) + @ApiBody({ + description: 'Es obligatorio enviar el campo id_usuario.', + examples: { ejemplo: { value: { id_usuario: 1 } } }, + }) passwordResset(@Body() body: UsuarioUpdateDto) { return this.usuarioService.passwordReset(body.id_usuario); } @Get('usuario') // @UseGuards(AuthGuard('jwt')) + @ApiOperation({ + description: 'Enpoint que retorna la información de un usuario.', + }) + @ApiQuery({ + description: 'El id del usuario.', + name: 'id_usuario', + type: 'string', + }) usuario(@Query() query: UsuarioDto) { return this.usuarioService.findById(parseInt(query.id_usuario), true, true); } @Get('usuarios') // @UseGuards(AuthGuard('jwt')) + @ApiOperation({ + description: + 'Endpoint que retorna 25 usuarios dependiendo de la página en la que se encuentra el usuario y sus filtros.', + }) + @ApiQuery({ + description: 'Página en la que se encuentra el usuario.', + name: 'pagina', + type: 'string', + }) + @ApiQuery({ + description: 'Id de la institución que se queire usar como filtro.', + name: 'id_institucion', + type: 'string', + required: false, + }) + @ApiQuery({ + description: 'Id de la carrera que se queire usar como filtro.', + name: 'id_carrera', + type: 'string', + required: false, + }) + @ApiQuery({ + description: 'Id del tipo usuario que se queire usar como filtro.', + name: 'id_tipo_usuario', + type: 'string', + required: false, + }) + @ApiQuery({ + description: 'Nombre del usuario que se queire buscar.', + name: 'nombre', + type: 'string', + required: false, + }) + @ApiQuery({ + description: 'Usuario que se queire buscar.', + name: 'usuario', + type: 'string', + required: false, + }) usuarios(@Query() query: UsuarioUsuariosDto) { return this.usuarioService.findAll(query); }