correiciones

This commit is contained in:
2021-09-02 16:13:16 -05:00
parent 7f44e197e8
commit ded01c50d3
4 changed files with 39 additions and 13 deletions
+19 -8
View File
@@ -1,6 +1,7 @@
const validar = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Reporte = require(`${dbPath}/Reporte`);
const Operador = require(`${dbPath}/Operador`);
const Prestamo = require(`${dbPath}/Prestamo`);
const historialReportes = async (body) => {
@@ -8,19 +9,29 @@ const historialReportes = async (body) => {
const pagina = validar.validarNumero(body.pagina, true);
return Reporte.findAndCountAll({
// where: { idEquipo },
include: [{ model: Prestamo }],
where: { idEquipo },
include: [{ model: Prestamo }, { model: Operador }],
limit: 25,
offset: 25 * (pagina - 1),
order: [['createdAt', 'DESC']],
}).then((res) => {
for (let i = 0; i < res.rows.length; i++) {
// delete res.rows[i].dataValues.idInfraccion;
// delete res.rows[i].dataValues.idPrestamo;
// delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorEntrega;
// delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorRegreso;
// delete res.rows[i].dataValues.Prestamo.dataValues.idUsuario;
// delete res.rows[i].dataValues.Prestamo.dataValues.idEquipo;
delete res.rows[i].dataValues.idPrestamo;
delete res.rows[i].dataValues.idEquipo;
delete res.rows[i].dataValues.idOperador;
if (res.rows[i].dataValues.Prestamo) {
delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorEntrega;
delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorRegreso;
delete res.rows[i].dataValues.Prestamo.dataValues.idUsuario;
delete res.rows[i].dataValues.Prestamo.dataValues.idEquipo;
delete res.rows[i].dataValues.Operador;
}
if (res.rows[i].dataValues.Operador) {
delete res.rows[i].dataValues.Operador.dataValues.password;
delete res.rows[i].dataValues.Operador.dataValues.idTipoUsuario;
delete res.rows[i].dataValues.Operador.dataValues.activo;
delete res.rows[i].dataValues.Prestamo;
}
}
return { count: res.count, historialReportes: res.rows };
});
+1 -1
View File
@@ -2,11 +2,11 @@ const { validarId, validarTexto } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Reporte = require(`${dbPath}/Reporte`);
const Prestamo = require(`${dbPath}/Prestamo`);
let idEquipo = null;
const reportar = async (body) => {
const idPrestamo = validarId(body.idPrestamo);
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
let idEquipo = null;
return Prestamo.findOne({ where: { idPrestamo } })
.then((res) => {
+9 -4
View File
@@ -1,17 +1,22 @@
const { validarId, validarTexto } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Reporte = require(`${dbPath}/Reporte`);
const Equipo = require(`${dbPath}/Equipo`);
const Operador = require(`${dbPath}/Operador`);
const Reporte = require(`${dbPath}/Reporte`);
const reportar = async (body) => {
console.log(body);
const idOperador = validarId(body.idOperador);
const idEquipo = validarId(body.idEquipo);
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
return Equipo.findOne({ where: { idEquipo } })
return Operador.findOne({ where: { idOperador } })
.then((res) => {
if (!res) throw new Error('No existe este operador.');
return Equipo.findOne({ where: { idEquipo } });
})
.then((res) => {
if (!res) throw new Error('No existe este equipo.');
return Reporte.create({ descripcion, idEquipo });
return Reporte.create({ descripcion, idEquipo, idOperador });
})
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
};