operador listo, solo falta reporte
This commit is contained in:
parent
233089cbf1
commit
63d83d46e2
@ -66,7 +66,7 @@ import { Usuario } from './usuario/entity/usuario.entity';
|
||||
database: configService.get<string>('DB'),
|
||||
username: configService.get<string>('DB_USER'),
|
||||
password: configService.get<string>('DB_PASSWORD'),
|
||||
port: Number(configService.get<string>('DB_PORT')),
|
||||
port: parseInt(configService.get<string>('DB_PORT')),
|
||||
synchronize: true,
|
||||
entities: [
|
||||
Carrera,
|
||||
|
@ -23,8 +23,11 @@ export class AuthService {
|
||||
validate() {}
|
||||
|
||||
loginAdmin(admin: string, password: string) {
|
||||
return this.operadorService.findByAdmin(admin, false).then((operador) => {
|
||||
if (!operador || !this.bcryptService.comparar(password, operador.password))
|
||||
return this.operadorService.findAdmin(admin, false).then((operador) => {
|
||||
if (
|
||||
!operador ||
|
||||
!this.bcryptService.comparar(password, operador.password)
|
||||
)
|
||||
throw new UnauthorizedException(
|
||||
'Usuario y/o password incorrectos, trata de nuevo.',
|
||||
);
|
||||
@ -51,7 +54,7 @@ export class AuthService {
|
||||
const modulo = await this.moduloService.findById(id_modulo);
|
||||
|
||||
return this.operadorService
|
||||
.findByOperador(operador, id_institucion)
|
||||
.findByOperador(id_institucion, operador)
|
||||
.then((operador) => {
|
||||
if (
|
||||
!operador ||
|
||||
|
@ -8,7 +8,7 @@ export class BcryptService {
|
||||
|
||||
encriptar(password: string) {
|
||||
const salt = bcrypt.genSaltSync(
|
||||
Number(this.configService.get<string>('SALT_ROUNDS')),
|
||||
parseInt(this.configService.get<string>('SALT_ROUNDS')),
|
||||
);
|
||||
|
||||
return bcrypt.hashSync(password, salt);
|
||||
|
@ -20,9 +20,9 @@ export class CarreraService {
|
||||
});
|
||||
}
|
||||
|
||||
findByCarrera(carrera: string, noExisteValidar = true) {
|
||||
findByCarrera(carrera: string, validarNoExiste = true) {
|
||||
return this.repository.findOne({ carrera }).then((carrera) => {
|
||||
if (noExisteValidar && !carrera)
|
||||
if (validarNoExiste && !carrera)
|
||||
throw new NotFoundException('No existe esta carrera.');
|
||||
return carrera;
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ export class CarritoController {
|
||||
|
||||
@Get('carrito')
|
||||
carrito(@Query() query: CarritoDto) {
|
||||
return this.carritoService.findById(Number(query.id_carrito));
|
||||
return this.carritoService.findById(parseInt(query.id_carrito));
|
||||
}
|
||||
|
||||
@Get('carritos')
|
||||
|
@ -74,10 +74,10 @@ export class CarritoService {
|
||||
} = {}
|
||||
|
||||
const modulo = filtros.id_modulo
|
||||
? await this.moduloService.findById(Number(filtros.id_modulo))
|
||||
? await this.moduloService.findById(parseInt(filtros.id_modulo))
|
||||
: null;
|
||||
const institucionTipoCarrito = filtros.id_tipo_carrito
|
||||
? await this.institucionTipoCarritoService.findById(Number(filtros.id_tipo_carrito))
|
||||
? await this.institucionTipoCarritoService.findById(parseInt(filtros.id_tipo_carrito))
|
||||
: null
|
||||
|
||||
if (filtros.activo) busqueda.activo = filtros.activo;
|
||||
|
@ -19,7 +19,7 @@ export class EquipoController {
|
||||
|
||||
@Get('equipo')
|
||||
equipo(@Query() query: EquipoDto) {
|
||||
return this.equipoService.findById(Number(query.id_equipo));
|
||||
return this.equipoService.findById(parseInt(query.id_equipo));
|
||||
}
|
||||
|
||||
// Terminar uwu
|
||||
|
@ -9,7 +9,7 @@ export class InstitucionCarreraController {
|
||||
@Get()
|
||||
get(@Query() query: InstitucionCarreraDto) {
|
||||
return this.institucionCarreraService.findAllByIdInstitucion(
|
||||
Number(query.id_institucion),
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ export class InstitucionDiaController {
|
||||
@Get('instituciones_dias')
|
||||
institucionesDias(@Query() query: IdInstitucionDto) {
|
||||
return this.institucionDiaService.findAllByIdInstitucion(
|
||||
Number(query.id_institucion),
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ export class InstitucionInfraccionController {
|
||||
@Get('institucion_infracciones')
|
||||
institucionInfracciones(@Query() query: IdInstitucionDto) {
|
||||
return this.institucionInfraccionService.findAllByIdInstitucion(
|
||||
Number(query.id_institucion),
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,14 @@ export class InstitucionTipoCarritoController {
|
||||
@Get('institucion_tipos_carritos')
|
||||
institucionTiposCarritos(@Query() query: IdInstitucionDto) {
|
||||
return this.institucionTipoCarritoService.findAllByIdInstitucion(
|
||||
Number(query.id_institucion),
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
@Get('institucion_tipos_carritos_mostar')
|
||||
institucionTiposCarritosMostrar(@Query() query: IdInstitucionDto) {
|
||||
return this.institucionTipoCarritoService.findAllByIdInstitucionMostar(
|
||||
Number(query.id_institucion),
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ export class InstitucionController {
|
||||
|
||||
@Get('institucion')
|
||||
institucion(@Query() query: IdInstitucionDto) {
|
||||
return this.institucionService.findById(Number(query.id_institucion));
|
||||
return this.institucionService.findById(parseInt(query.id_institucion));
|
||||
}
|
||||
|
||||
@Put()
|
||||
|
@ -24,7 +24,7 @@ export class ModuloController {
|
||||
@Get('modulos')
|
||||
modulos(@Query() query: IdInstitucionDto) {
|
||||
return this.moduloService.findAllByIdInstitucion(
|
||||
Number(query.id_institucion),
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ export class MotivoController {
|
||||
|
||||
@Get()
|
||||
get(@Query() query: MotivoDto) {
|
||||
return this.motivoService.findAllIdEquipo(Number(query.id_equipo));
|
||||
return this.motivoService.findAllIdEquipo(parseInt(query.id_equipo));
|
||||
}
|
||||
|
||||
@Get('reporte')
|
||||
|
@ -4,6 +4,9 @@ export class OperadorCreateDto {
|
||||
@IsInt()
|
||||
id_institucion: number;
|
||||
|
||||
@IsInt()
|
||||
id_tipo_usuario: number;
|
||||
|
||||
@IsString()
|
||||
operador: string;
|
||||
|
||||
|
@ -8,6 +8,10 @@ export class OperadorOperadoresDto {
|
||||
@IsOptional()
|
||||
id_institucion?: string;
|
||||
|
||||
@IsNumberString()
|
||||
@IsOptional()
|
||||
id_tipo_usuario: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
operador?: string;
|
||||
|
@ -8,10 +8,6 @@ export class OperadorUpdateDto {
|
||||
@IsOptional()
|
||||
activo?: boolean;
|
||||
|
||||
// @IsString()
|
||||
// @IsOptional()
|
||||
// operador?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
password?: string;
|
||||
|
@ -4,17 +4,21 @@ import { OperadorCreateDto } from './dto/operador-create.dto';
|
||||
import { OperadorOperadoresDto } from './dto/operador-operadores.dto';
|
||||
import { OperadorUpdateDto } from './dto/operador-update.dto';
|
||||
import { OperadorDto } from './dto/operador.dto';
|
||||
import {ApiTags} from '@nestjs/swagger'
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@Controller('operador')
|
||||
@ApiTags('operador')
|
||||
export class OperadorController {
|
||||
constructor(private operadorService: OperadorService) {}
|
||||
|
||||
@Get('admins')
|
||||
admins() {}
|
||||
|
||||
@Post()
|
||||
create(@Body() body: OperadorCreateDto) {
|
||||
return this.operadorService.create(
|
||||
body.id_institucion,
|
||||
body.id_tipo_usuario,
|
||||
body.operador,
|
||||
body.password,
|
||||
);
|
||||
@ -22,7 +26,7 @@ export class OperadorController {
|
||||
|
||||
@Get('operador')
|
||||
operador(@Query() query: OperadorDto) {
|
||||
return this.operadorService.findById(Number(query.id_operador));
|
||||
return this.operadorService.findById(parseInt(query.id_operador));
|
||||
}
|
||||
|
||||
@Get('operadores')
|
||||
@ -30,8 +34,8 @@ export class OperadorController {
|
||||
return this.operadorService.findAll(query);
|
||||
}
|
||||
|
||||
@Get('reporte')
|
||||
reporte() {}
|
||||
// @Get('reporte')
|
||||
// reporte() {}
|
||||
|
||||
@Put()
|
||||
update(@Body() body: OperadorUpdateDto) {
|
||||
|
@ -4,9 +4,10 @@ import {
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Between, Repository } from 'typeorm';
|
||||
import { Operador } from './entity/operador.entity';
|
||||
import { Between, FindOperator, Like, Repository } from 'typeorm';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { Operador } from './entity/operador.entity';
|
||||
import { TipoUsuario } from 'src/tipo-usuario/entity/tipo-usuario.entity';
|
||||
import { BcryptService } from '../bcrypt/bcrypt.service';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
||||
@ -20,12 +21,16 @@ export class OperadorService {
|
||||
private tipoUsuarioService: TipoUsuarioService,
|
||||
) {}
|
||||
|
||||
async create(id_institucion: number, operador: string, password: string) {
|
||||
async create(
|
||||
id_institucion: number,
|
||||
id_tipo_usuario: number,
|
||||
operador: string,
|
||||
password: string,
|
||||
) {
|
||||
const institucion = await this.institucionService.findById(id_institucion);
|
||||
const tipoUsuario = await this.tipoUsuarioService.findById(4);
|
||||
const tipoUsuario = await this.tipoUsuarioService.findById(id_tipo_usuario);
|
||||
|
||||
return this.repository
|
||||
.findOne({ operador, institucion })
|
||||
return this.findByOperador(institucion, operador, false)
|
||||
.then(async (existeOperador) => {
|
||||
if (existeOperador)
|
||||
throw new ConflictException(
|
||||
@ -44,38 +49,54 @@ export class OperadorService {
|
||||
.then((_) => ({ message: 'Se creo correctamente al operador.' }));
|
||||
}
|
||||
|
||||
async findAll(filtros: {
|
||||
pagina: string;
|
||||
id_institucion?: string;
|
||||
operador?: string;
|
||||
}) {
|
||||
const busqueda: { operador?: string; institucion?: Institucion } = {};
|
||||
const institucion = filtros.id_institucion
|
||||
? await this.institucionService.findById(Number(filtros.id_institucion))
|
||||
: null;
|
||||
|
||||
/* buscar like */
|
||||
if (filtros.operador) busqueda.operador = filtros.operador;
|
||||
if (institucion) busqueda.institucion = institucion;
|
||||
/* falta página */
|
||||
return this.repository.find(busqueda);
|
||||
}
|
||||
|
||||
findByAdmin(admin: string, noExisteValidar = true) {
|
||||
findAdmin(admin: string, validarNoExiste = true) {
|
||||
return this.repository
|
||||
.findOne({
|
||||
where: {
|
||||
operador: admin,
|
||||
tipoUsuario: { id_tipo_usuario: Between(2, 3) },
|
||||
},
|
||||
operador: admin,
|
||||
tipoUsuario: { id_tipo_usuario: Between(2, 3) },
|
||||
})
|
||||
.then((admin) => {
|
||||
if (noExisteValidar && !admin)
|
||||
if (validarNoExiste && !admin)
|
||||
throw new NotFoundException('No existe este admin.');
|
||||
return admin;
|
||||
});
|
||||
}
|
||||
|
||||
async findAll(filtros: {
|
||||
pagina: string;
|
||||
id_institucion?: string;
|
||||
id_tipo_usuario?: string;
|
||||
operador?: string;
|
||||
}) {
|
||||
const busqueda: {
|
||||
where: {
|
||||
institucion?: Institucion;
|
||||
operador?: FindOperator<string>;
|
||||
tipoUsuario?: TipoUsuario;
|
||||
};
|
||||
skip;
|
||||
take;
|
||||
} = {
|
||||
where: {},
|
||||
skip: (parseInt(filtros.pagina) - 1) * 25,
|
||||
take: 25,
|
||||
};
|
||||
const institucion = filtros.id_institucion
|
||||
? await this.institucionService.findById(parseInt(filtros.id_institucion))
|
||||
: null;
|
||||
const tipoUsuario = filtros.id_tipo_usuario
|
||||
? await this.tipoUsuarioService.findById(
|
||||
parseInt(filtros.id_tipo_usuario),
|
||||
)
|
||||
: null;
|
||||
|
||||
if (filtros.operador)
|
||||
busqueda.where.operador = Like(`${filtros.operador}%`);
|
||||
if (institucion) busqueda.where.institucion = institucion;
|
||||
if (tipoUsuario) busqueda.where.tipoUsuario = tipoUsuario;
|
||||
return this.repository.find(busqueda);
|
||||
}
|
||||
|
||||
findById(id_operador: number) {
|
||||
return this.repository.findOne({ id_operador }).then((operador) => {
|
||||
if (!operador) throw new NotFoundException('No existe este operador');
|
||||
@ -83,16 +104,20 @@ export class OperadorService {
|
||||
});
|
||||
}
|
||||
|
||||
findByOperador(
|
||||
async findByOperador(
|
||||
id_institucion: number | Institucion,
|
||||
operador: string,
|
||||
id_institucion: number,
|
||||
noExisteValidar = true,
|
||||
validarNoExiste = true,
|
||||
) {
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) => this.repository.findOne({ institucion, operador }))
|
||||
const institucion =
|
||||
typeof id_institucion === 'number'
|
||||
? await this.institucionService.findById(id_institucion)
|
||||
: id_institucion;
|
||||
|
||||
return this.repository
|
||||
.findOne({ institucion, operador })
|
||||
.then((operador) => {
|
||||
if (noExisteValidar && !operador)
|
||||
if (validarNoExiste && !operador)
|
||||
throw new NotFoundException('No existe este operador.');
|
||||
return operador;
|
||||
});
|
||||
|
@ -21,6 +21,6 @@ export class ProgramaController {
|
||||
|
||||
@Get('programa')
|
||||
programa(@Query() query: ProgramaDto) {
|
||||
return this.programaService.findById(Number(query.id_programa))
|
||||
return this.programaService.findById(parseInt(query.id_programa))
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ export class TipoUsuarioService {
|
||||
});
|
||||
}
|
||||
|
||||
findByTipoUsuario(tipo_usuario: string, noExisteValidar = true) {
|
||||
findByTipoUsuario(tipo_usuario: string, validarNoExiste = true) {
|
||||
return this.repository.findOne({ tipo_usuario }).then((tipoUsuario) => {
|
||||
if (noExisteValidar && !tipoUsuario)
|
||||
if (validarNoExiste && !tipoUsuario)
|
||||
throw new NotFoundException('No existe este tipo usuairo');
|
||||
return tipoUsuario;
|
||||
});
|
||||
|
@ -25,7 +25,7 @@ export class UploadFileController {
|
||||
) {
|
||||
return this.uploadFileService.createEquipos(
|
||||
file,
|
||||
Number(query.id_institucion),
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
@ -37,13 +37,13 @@ export class UploadFileController {
|
||||
) {
|
||||
return this.uploadFileService.createUsuarios(
|
||||
file,
|
||||
Number(query.id_institucion),
|
||||
parseInt(query.id_institucion),
|
||||
);
|
||||
}
|
||||
|
||||
@Get('download-logo')
|
||||
downloadLogo(@Response() res, @Query() query: IdInstitucionDto) {
|
||||
return this.uploadFileService.downloadLogo(Number(query.id_institucion));
|
||||
return this.uploadFileService.downloadLogo(parseInt(query.id_institucion));
|
||||
}
|
||||
|
||||
@Get('download-plantilla-equipos')
|
||||
@ -62,6 +62,6 @@ export class UploadFileController {
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
@Query() query: IdInstitucionDto,
|
||||
) {
|
||||
this.uploadFileService.uploadLogo(file, Number(query.id_institucion));
|
||||
this.uploadFileService.uploadLogo(file, parseInt(query.id_institucion));
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ export class UsuarioController {
|
||||
@Get('usuario')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
usuario(@Query() query: UsuarioDto) {
|
||||
return this.usuarioService.findById(Number(query.id_usuario));
|
||||
return this.usuarioService.findById(parseInt(query.id_usuario));
|
||||
}
|
||||
|
||||
@Get('usuarios')
|
||||
|
@ -94,13 +94,13 @@ export class UsuarioService {
|
||||
usuario?: string;
|
||||
} = {};
|
||||
const institucion = filtros.id_institucion
|
||||
? await this.institucionService.findById(Number(filtros.id_institucion))
|
||||
? await this.institucionService.findById(parseInt(filtros.id_institucion))
|
||||
: null;
|
||||
const tipoUsuario = filtros.id_tipo_usuario
|
||||
? await this.tipoUsuarioService.findById(Number(filtros.id_tipo_usuario))
|
||||
? await this.tipoUsuarioService.findById(parseInt(filtros.id_tipo_usuario))
|
||||
: null;
|
||||
const carrera = filtros.id_carrera
|
||||
? await this.carreraService.findById(Number(filtros.id_carrera))
|
||||
? await this.carreraService.findById(parseInt(filtros.id_carrera))
|
||||
: null;
|
||||
|
||||
/* buscar usnado like */
|
||||
@ -112,17 +112,17 @@ export class UsuarioService {
|
||||
return this.repository.find(busqueda);
|
||||
}
|
||||
|
||||
findById(id_usuario: number, noExisteValidar = true, password = false) {
|
||||
findById(id_usuario: number, validarNoExiste = true, password = false) {
|
||||
return this.repository.findOne({ id_usuario }).then((usuario) => {
|
||||
if (noExisteValidar && (!usuario || (password && !usuario.password)))
|
||||
if (validarNoExiste && (!usuario || (password && !usuario.password)))
|
||||
throw new NotFoundException('No existe este usuario.');
|
||||
return usuario;
|
||||
});
|
||||
}
|
||||
|
||||
findByUsuario(usuario: string, noExisteValidar = true, password = false) {
|
||||
findByUsuario(usuario: string, validarNoExiste = true, password = false) {
|
||||
return this.repository.findOne({ usuario }).then((usuario) => {
|
||||
if (noExisteValidar && (!usuario || (password && !usuario.password)))
|
||||
if (validarNoExiste && (!usuario || (password && !usuario.password)))
|
||||
throw new NotFoundException('No existe este usuario.');
|
||||
return usuario;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user