verificacion de ciertos endpoints
This commit is contained in:
parent
9c7353a91e
commit
7c71d5178c
@ -1,7 +1,6 @@
|
||||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { CarreraService } from './carrera.service';
|
||||
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { CarreraService } from './carrera.service';
|
||||
|
||||
@Controller('carrera')
|
||||
@ApiTags('carrera')
|
||||
|
@ -21,13 +21,13 @@ export class ModuloController {
|
||||
constructor(private moduloService: ModuloService) {}
|
||||
|
||||
@Post()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
create(@Body() body: ModuloCreateDto) {
|
||||
return this.moduloService.create(body.id_institucion, body.modulo);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
get() {
|
||||
return this.moduloService.findAll();
|
||||
}
|
||||
@ -40,7 +40,7 @@ export class ModuloController {
|
||||
}
|
||||
|
||||
@Put()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
update(@Body() body: ModuloUpdateDto) {
|
||||
return this.moduloService.update(body);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export class OperadorController {
|
||||
constructor(private operadorService: OperadorService) {}
|
||||
|
||||
@Post()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
create(@Body() body: OperadorCreateDto) {
|
||||
return this.operadorService.create(
|
||||
body.id_institucion,
|
||||
@ -32,13 +32,13 @@ export class OperadorController {
|
||||
}
|
||||
|
||||
@Get('operador')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
operador(@Query() query: OperadorDto) {
|
||||
return this.operadorService.findById(parseInt(query.id_operador));
|
||||
}
|
||||
|
||||
@Get('operadores')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
operadores(@Query() query: OperadorOperadoresDto) {
|
||||
return this.operadorService.findAll(query);
|
||||
}
|
||||
@ -48,7 +48,7 @@ export class OperadorController {
|
||||
// reporte() {}
|
||||
|
||||
@Put()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
update(@Body() body: OperadorUpdateDto) {
|
||||
return this.operadorService.update(body);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import {
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Between, FindOperator, Like, Repository } from 'typeorm';
|
||||
import { Between, FindOperator, Like, MoreThan, Repository } from 'typeorm';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { Operador } from './entity/operador.entity';
|
||||
import { TipoUsuario } from '../tipo-usuario/entity/tipo-usuario.entity';
|
||||
@ -30,19 +30,19 @@ export class OperadorService {
|
||||
const institucion = await this.institucionService.findById(id_institucion);
|
||||
const tipoUsuario = await this.tipoUsuarioService.findById(id_tipo_usuario);
|
||||
|
||||
return this.findByOperador(institucion, operador, false)
|
||||
.then(async (existeOperador) => {
|
||||
if (existeOperador)
|
||||
throw new ConflictException(
|
||||
'Ya existe un operador con ese nombre, intente de nuevo.',
|
||||
);
|
||||
return this.findAdmin(operador, false);
|
||||
})
|
||||
return this.findAdmin(operador, false)
|
||||
.then((existeAdmin) => {
|
||||
if (existeAdmin)
|
||||
throw new ConflictException(
|
||||
'Ya existe un admin con ese nombre, intente de nuevo.',
|
||||
);
|
||||
return this.findByOperador(institucion, operador, false);
|
||||
})
|
||||
.then(async (existeOperador) => {
|
||||
if (existeOperador)
|
||||
throw new ConflictException(
|
||||
'Ya existe un operador con ese nombre, intente de nuevo.',
|
||||
);
|
||||
password = this.bcryptService.encriptar(password);
|
||||
return this.repository.save(
|
||||
this.repository.create({
|
||||
@ -106,7 +106,7 @@ export class OperadorService {
|
||||
|
||||
findById(id_operador: number) {
|
||||
return this.repository.findOne({ id_operador }).then((operador) => {
|
||||
if (!operador) throw new NotFoundException('No existe este operador');
|
||||
if (!operador) throw new NotFoundException('No existe este operador.');
|
||||
return operador;
|
||||
});
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { ProgramaService } from './programa.service';
|
||||
import { ProgramaCreateDto } from './dto/programa-create.dto';
|
||||
import { ProgramaDto } from './dto/programa.dto'
|
||||
import {ApiTags} from '@nestjs/swagger'
|
||||
import { ProgramaDto } from './dto/programa.dto';
|
||||
|
||||
@Controller('programa')
|
||||
@ApiTags('programa')
|
||||
@ -21,6 +21,6 @@ export class ProgramaController {
|
||||
|
||||
@Get('programa')
|
||||
programa(@Query() query: ProgramaDto) {
|
||||
return this.programaService.findById(parseInt(query.id_programa))
|
||||
return this.programaService.findById(parseInt(query.id_programa));
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { UploadFileService } from './upload-file.service';
|
||||
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
||||
import {ApiTags} from '@nestjs/swagger'
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@Controller('upload-file')
|
||||
@ApiTags('upload-file')
|
||||
@ -47,12 +47,12 @@ export class UploadFileController {
|
||||
}
|
||||
|
||||
@Get('download-plantilla-equipos')
|
||||
downloadPlantillaEquipos(@Response() res, @Query() query: IdInstitucionDto) {
|
||||
downloadPlantillaEquipos(@Response() res) {
|
||||
return res.download('./upload/plantilla_equipos.csv');
|
||||
}
|
||||
|
||||
@Get('download-plantilla-usuarios')
|
||||
downloadPlantillaUsuarios(@Response() res, @Query() query: IdInstitucionDto) {
|
||||
downloadPlantillaUsuarios(@Response() res) {
|
||||
return res.download('./upload/plantilla_alumnos.csv');
|
||||
}
|
||||
|
||||
|
@ -38,26 +38,33 @@ export class UploadFileService {
|
||||
const institucion = await this.institucionService.findById(id_institucion);
|
||||
const errores: string[] = [];
|
||||
|
||||
if (!file) throw new BadRequestException('No se mando un archivo.');
|
||||
// if (!file) throw new BadRequestException('No se mando un archivo.');
|
||||
return csvtojson()
|
||||
.fromFile(path)
|
||||
.then(async (usuarios: [UploadFileCargaMasivaUsuarioDto]) => {
|
||||
for (let i = 0; i < usuarios.length; i++) {
|
||||
if (!usuarios[i].numero_cuenta || !usuarios[i].tipo_usuario) {
|
||||
let error = this.errorBase(i);
|
||||
|
||||
if (
|
||||
!usuarios[i].numero_cuenta ||
|
||||
!usuarios[i].tipo_usuario ||
|
||||
!usuarios[i].nombres ||
|
||||
!usuarios[i].apellido_m ||
|
||||
!usuarios[i].apellido_p
|
||||
) {
|
||||
if (!usuarios[i].numero_cuenta)
|
||||
errores.push(
|
||||
`${this.errorBase(i)} falta del campo numero_cuenta.`,
|
||||
);
|
||||
error += ' falta del campo numero_cuenta';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!usuarios[i].tipo_usuario)
|
||||
errores.push(
|
||||
`${this.errorBase(i)} falta del campo tipo_usuario.`,
|
||||
);
|
||||
if (!usuarios[i].nombres)
|
||||
errores.push(`${this.errorBase(i)} falta del campo nombres.`);
|
||||
if (!usuarios[i].apellido_m)
|
||||
errores.push(`${this.errorBase(i)} falta del campo apellido_m.`);
|
||||
if (!usuarios[i].apellido_p)
|
||||
errores.push(`${this.errorBase(i)} falta del campo apellido_p.`);
|
||||
error += ' falta del campo tipo_usuario';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!usuarios[i].nombres) error += ' falta del campo nombres';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!usuarios[i].apellido_m) error += ' falta del campo apellido_m';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!usuarios[i].apellido_p) error += ' falta del campo apellido_p';
|
||||
error += '.';
|
||||
errores.push(error);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -65,35 +72,26 @@ export class UploadFileService {
|
||||
usuarios[i].tipo_usuario,
|
||||
false,
|
||||
);
|
||||
const carrera =
|
||||
usuarios[i].carrera && tipoUsuario.id_tipo_usuario !== 5
|
||||
? await this.carreraService
|
||||
.findByCarrera(usuarios[i].carrera, false)
|
||||
.then((carrera) => {
|
||||
if (!carrera)
|
||||
// return this.carreraService.create(
|
||||
// institucion.id_institucion,
|
||||
// usuarios[i].carrera,
|
||||
// );
|
||||
return carrera;
|
||||
})
|
||||
: null;
|
||||
const usuario = await this.usuarioService.findByUsuario(
|
||||
usuarios[i].numero_cuenta,
|
||||
false,
|
||||
);
|
||||
const carrera =
|
||||
usuarios[i].carrera && tipoUsuario.id_tipo_usuario > 5
|
||||
? await this.carreraService.findByCarrera(
|
||||
usuarios[i].carrera,
|
||||
false,
|
||||
)
|
||||
: null;
|
||||
|
||||
console.log('hola');
|
||||
console.log(usuario);
|
||||
if (!tipoUsuario || (tipoUsuario.id_tipo_usuario !== 5 && !carrera)) {
|
||||
if (!tipoUsuario || (tipoUsuario.id_tipo_usuario > 5 && !carrera)) {
|
||||
if (tipoUsuario.id_tipo_usuario !== 5 && !carrera)
|
||||
errores.push(
|
||||
`${this.errorBase(i)} falta del campo carrera para el alumno.`,
|
||||
);
|
||||
if (!tipoUsuario)
|
||||
errores.push(
|
||||
`${this.errorBase(i)} no existe este tipo de usuario.`,
|
||||
);
|
||||
error += ' falta del campo carrera para el alumno';
|
||||
if (error != this.errorBase(i)) error += ',';
|
||||
if (!tipoUsuario) error += ' no existe este tipo de usuario';
|
||||
error += '.';
|
||||
errores.push(error);
|
||||
continue;
|
||||
}
|
||||
if (usuario) {
|
||||
|
@ -22,10 +22,10 @@ export class UsuarioController {
|
||||
constructor(private usuarioService: UsuarioService) {}
|
||||
|
||||
/* Pendiente por conexión */
|
||||
@Get('dgae-dgp')
|
||||
dgaeDgp(@Query() query: UsuarioEscolaresDto) {
|
||||
return this.usuarioService.dgaeDgp(query.usuario);
|
||||
}
|
||||
// @Get('dgae-dgp')
|
||||
// dgaeDgp(@Query() query: UsuarioEscolaresDto) {
|
||||
// return this.usuarioService.dgaeDgp(query.usuario);
|
||||
// }
|
||||
|
||||
@Post('registrar')
|
||||
registrar(@Body() body: UsuarioRegistrarDto) {
|
||||
@ -33,25 +33,25 @@ export class UsuarioController {
|
||||
}
|
||||
|
||||
@Put()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
update(@Body() body: UsuarioUpdateDto) {
|
||||
return this.usuarioService.update(body);
|
||||
}
|
||||
|
||||
@Put('update-password')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
passwordResset(@Body() body: UsuarioUpdateDto) {
|
||||
return this.usuarioService.passwordReset(body.id_usuario);
|
||||
}
|
||||
|
||||
@Get('usuario')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
usuario(@Query() query: UsuarioDto) {
|
||||
return this.usuarioService.findById(parseInt(query.id_usuario));
|
||||
return this.usuarioService.findById(parseInt(query.id_usuario), true, true);
|
||||
}
|
||||
|
||||
@Get('usuarios')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
usuarios(@Query() query: UsuarioUsuariosDto) {
|
||||
return this.usuarioService.findAll(query);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user