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