183 lines
5.0 KiB
TypeScript
183 lines
5.0 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { ApiBody, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
|
import { Serealize } from '../interceptors/serialize.interceptor';
|
|
import { UsuarioService } from './usuario.service';
|
|
import { UsuarioDgaeDto } from './dto/input/dgae.dto';
|
|
import { UsuarioDgpDto } from './dto/input/dgp.dto';
|
|
import { UsuarioRegistrarDto } from './dto/input/registrar.dto';
|
|
import { UsuarioUpdateDto } from './dto/input/update.dto';
|
|
import { UsuarioUsuariosDto } from './dto/input/usuarios.dto';
|
|
import { UsuarioDto } from './dto/input/usuario.dto';
|
|
import { EscolaresOutputDto } from './dto/output/escolares.dto';
|
|
import { UsuarioOutputDto } from './dto/output/usuario.dto';
|
|
import { UsuariosOutputDto } from './dto/output/usuarios.dto';
|
|
|
|
@Controller('usuario')
|
|
@ApiTags('usuario')
|
|
export class UsuarioController {
|
|
constructor(private usuarioService: UsuarioService) {}
|
|
|
|
@Serealize(EscolaresOutputDto)
|
|
@Get('dgae')
|
|
@ApiOperation({
|
|
description: 'Endpoint que retorna información de dgae de un alumno.',
|
|
})
|
|
@ApiQuery({
|
|
description: 'Número de cuenta del alumno.',
|
|
name: 'usuario',
|
|
type: 'string',
|
|
})
|
|
@ApiQuery({
|
|
description: 'Id de la carrera institución a la que pertenece el alumno.',
|
|
name: 'id_institucion_carrera',
|
|
type: 'string',
|
|
})
|
|
dgae(@Query() query: UsuarioDgaeDto) {
|
|
return this.usuarioService.DGAE(
|
|
query.usuario,
|
|
parseInt(query.id_institucion_carrera),
|
|
);
|
|
}
|
|
|
|
@Serealize(EscolaresOutputDto)
|
|
@Get('dgp')
|
|
@ApiOperation({
|
|
description: 'Endpoint que retorna información de dgp de un profesor.',
|
|
})
|
|
@ApiQuery({
|
|
description: 'Número de cuenta del profesor.',
|
|
name: 'usuario',
|
|
type: 'string',
|
|
})
|
|
@ApiQuery({ description: 'RFC del profesor.', name: 'rfc', type: 'string' })
|
|
dgp(@Query() query: UsuarioDgpDto) {
|
|
return this.usuarioService.DGP(query.usuario, query.rfc);
|
|
}
|
|
|
|
@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,
|
|
body.correo,
|
|
);
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
@Serealize(UsuarioOutputDto)
|
|
@Get('usuario')
|
|
// @UseGuards(AuthGuard('jwt'))
|
|
@ApiOperation({
|
|
description: 'Enpoint que retorna la información de un usuario.',
|
|
})
|
|
@ApiQuery({
|
|
description: 'El número de cuenta que se quiere buscar.',
|
|
name: 'usuario',
|
|
type: 'string',
|
|
})
|
|
usuario(@Query() query: UsuarioDto) {
|
|
return this.usuarioService.findByUsuario(query.usuario, true, true);
|
|
}
|
|
|
|
@Serealize(UsuariosOutputDto)
|
|
@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 quiere usar como filtro.',
|
|
name: 'id_institucion',
|
|
type: 'string',
|
|
required: false,
|
|
})
|
|
@ApiQuery({
|
|
description: 'Id de la carrera que se quiere usar como filtro.',
|
|
name: 'id_carrera',
|
|
type: 'string',
|
|
required: false,
|
|
})
|
|
@ApiQuery({
|
|
description: 'Id del tipo usuario que se quiere usar como filtro.',
|
|
name: 'id_tipo_usuario',
|
|
type: 'string',
|
|
required: false,
|
|
})
|
|
@ApiQuery({
|
|
description: 'Nombre del usuario que se quiere buscar.',
|
|
name: 'nombre',
|
|
type: 'string',
|
|
required: false,
|
|
})
|
|
@ApiQuery({
|
|
description: 'Usuario que se quiere buscar.',
|
|
name: 'usuario',
|
|
type: 'string',
|
|
required: false,
|
|
})
|
|
usuarios(@Query() query: UsuarioUsuariosDto) {
|
|
return this.usuarioService.findAll(query);
|
|
}
|
|
}
|