correiciones
This commit is contained in:
@@ -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 };
|
||||
});
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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.' }));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user