opreador service final
This commit is contained in:
parent
d2f375ee63
commit
e8c71f05ef
@ -29,7 +29,7 @@ export class FullInformacionOperadorView {
|
|||||||
id_operador: number;
|
id_operador: number;
|
||||||
|
|
||||||
@ViewColumn()
|
@ViewColumn()
|
||||||
activo: boolean;
|
activo: number;
|
||||||
|
|
||||||
@ViewColumn()
|
@ViewColumn()
|
||||||
id_institucion: number;
|
id_institucion: number;
|
||||||
|
@ -134,7 +134,7 @@ export class OperadorController {
|
|||||||
const admin: Operador = req.user.operador;
|
const admin: Operador = req.user.operador;
|
||||||
|
|
||||||
this.validarUsuarioService.validarSuperAdminAdmin(admin);
|
this.validarUsuarioService.validarSuperAdminAdmin(admin);
|
||||||
return this.operadorService.findAll(query);
|
return this.operadorService.findAll(admin, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serealize(OperadorOutputDto)
|
@Serealize(OperadorOutputDto)
|
||||||
@ -148,7 +148,7 @@ export class OperadorController {
|
|||||||
const admin: Operador = req.user.operador;
|
const admin: Operador = req.user.operador;
|
||||||
|
|
||||||
this.validarUsuarioService.validarAdmin(admin);
|
this.validarUsuarioService.validarAdmin(admin);
|
||||||
return this.operadorService.findAllByInstitucion(admin.institucion);
|
return this.operadorService.findAllAdmin(admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serealize(MessageOutputDto)
|
@Serealize(MessageOutputDto)
|
||||||
|
@ -103,12 +103,15 @@ export class OperadorService {
|
|||||||
.then((admin) => this.llenarIds(admin));
|
.then((admin) => this.llenarIds(admin));
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(filtros: {
|
async findAll(
|
||||||
|
admin: Operador,
|
||||||
|
filtros: {
|
||||||
pagina: string;
|
pagina: string;
|
||||||
id_institucion?: string;
|
id_institucion?: string;
|
||||||
id_tipo_usuario?: string;
|
id_tipo_usuario?: string;
|
||||||
operador?: string;
|
operador?: string;
|
||||||
}): Promise<[Operador[], number]> {
|
},
|
||||||
|
): Promise<[Operador[], number]> {
|
||||||
const institucion = filtros.id_institucion
|
const institucion = filtros.id_institucion
|
||||||
? await this.institucionService.findById(parseInt(filtros.id_institucion))
|
? await this.institucionService.findById(parseInt(filtros.id_institucion))
|
||||||
: null;
|
: null;
|
||||||
@ -121,8 +124,10 @@ export class OperadorService {
|
|||||||
id_tipo_usuario: MoreThan(2),
|
id_tipo_usuario: MoreThan(2),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (admin.tipoUsuario.id_tipo_usuario > 2)
|
||||||
|
busqueda.id_institucion = admin.institucion.id_institucion;
|
||||||
|
else if (institucion) busqueda.id_institucion = institucion.id_institucion;
|
||||||
if (filtros.operador) busqueda.operador = Like(`${filtros.operador}%`);
|
if (filtros.operador) busqueda.operador = Like(`${filtros.operador}%`);
|
||||||
if (institucion) busqueda.id_institucion = institucion.id_institucion;
|
|
||||||
if (tipoUsuario) busqueda.id_tipo_usuario = tipoUsuario.id_tipo_usuario;
|
if (tipoUsuario) busqueda.id_tipo_usuario = tipoUsuario.id_tipo_usuario;
|
||||||
return this.fullInformacionOperadorView
|
return this.fullInformacionOperadorView
|
||||||
.findAndCount({
|
.findAndCount({
|
||||||
@ -137,7 +142,7 @@ export class OperadorService {
|
|||||||
operadores.push(
|
operadores.push(
|
||||||
this.repository.create({
|
this.repository.create({
|
||||||
id_operador: infoOperadores[0][i].id_operador,
|
id_operador: infoOperadores[0][i].id_operador,
|
||||||
activo: infoOperadores[0][i].activo,
|
activo: infoOperadores[0][i].activo === 1,
|
||||||
correo: infoOperadores[0][i].correo,
|
correo: infoOperadores[0][i].correo,
|
||||||
nombre: infoOperadores[0][i].nombre,
|
nombre: infoOperadores[0][i].nombre,
|
||||||
operador: infoOperadores[0][i].operador,
|
operador: infoOperadores[0][i].operador,
|
||||||
@ -155,21 +160,13 @@ export class OperadorService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findAllByInstitucion(institucion: Institucion): Promise<Operador[]> {
|
findAllAdmin(admin: Operador): Promise<Operador[]> {
|
||||||
return this.repository.find({
|
return this.repository.find({
|
||||||
select: ['id_operador', 'operador'],
|
select: ['id_operador', 'operador'],
|
||||||
where: { institucion },
|
where: { institucion: admin.institucion },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findOperador(institucion: Institucion, operador: string): Promise<Operador> {
|
|
||||||
return this.repository
|
|
||||||
.findOne({
|
|
||||||
where: { operador, institucion, tipoUsuario: { id_tipo_usuario: 4 } },
|
|
||||||
})
|
|
||||||
.then((operador) => this.llenarIds(operador));
|
|
||||||
}
|
|
||||||
|
|
||||||
findById(id_operador: number): Promise<Operador> {
|
findById(id_operador: number): Promise<Operador> {
|
||||||
return this.repository
|
return this.repository
|
||||||
.findOne({
|
.findOne({
|
||||||
@ -189,6 +186,14 @@ export class OperadorService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findOperador(institucion: Institucion, operador: string): Promise<Operador> {
|
||||||
|
return this.repository
|
||||||
|
.findOne({
|
||||||
|
where: { operador, institucion, tipoUsuario: { id_tipo_usuario: 4 } },
|
||||||
|
})
|
||||||
|
.then((operador) => this.llenarIds(operador));
|
||||||
|
}
|
||||||
|
|
||||||
llenarIds(operador: Operador): Operador {
|
llenarIds(operador: Operador): Operador {
|
||||||
if (operador) {
|
if (operador) {
|
||||||
operador.tipoUsuario = this.tipoUsuarioService.crearTipoUsuario(
|
operador.tipoUsuario = this.tipoUsuarioService.crearTipoUsuario(
|
||||||
@ -210,15 +215,15 @@ export class OperadorService {
|
|||||||
return this.findById(id_operador)
|
return this.findById(id_operador)
|
||||||
.then((operador) => {
|
.then((operador) => {
|
||||||
this.validarUpdate(admin, operador);
|
this.validarUpdate(admin, operador);
|
||||||
// Si no se manda una password se genera una
|
// Generamos un password por si no se mando uno
|
||||||
if (!password) password = this.bcryptService.generarPassword();
|
if (!password) password = this.bcryptService.generarPassword();
|
||||||
// Encriptación
|
// Encriptamos password
|
||||||
operador.password = this.bcryptService.encriptar(password);
|
operador.password = this.bcryptService.encriptar(password);
|
||||||
// Guardar
|
// Guardamos cambios
|
||||||
return this.repository.save(operador);
|
return this.repository.save(operador);
|
||||||
})
|
})
|
||||||
.then((operador) =>
|
.then((operador) =>
|
||||||
// Reenviar correo
|
// Enviamos un correo con credenciales
|
||||||
this.nodemailerService.sendEmail({
|
this.nodemailerService.sendEmail({
|
||||||
email: operador.correo,
|
email: operador.correo,
|
||||||
subject: 'Credenciales PC Puma',
|
subject: 'Credenciales PC Puma',
|
||||||
|
Loading…
Reference in New Issue
Block a user