hisotrial reportes y mutlas

This commit is contained in:
2021-09-02 14:55:56 -05:00
parent b1f7a15b2a
commit 7f44e197e8
5 changed files with 98 additions and 1 deletions
+4 -1
View File
@@ -2,6 +2,7 @@ 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);
@@ -10,11 +11,13 @@ const reportar = async (body) => {
return Prestamo.findOne({ where: { idPrestamo } })
.then((res) => {
if (!res) throw new Error('No existe este prestamo.');
console.log(res.dataValues);
idEquipo = res.idEquipo;
return Reporte.findOne({ where: { idPrestamo } });
})
.then((res) => {
if (res) throw new Error('Ya existe un reporte con este prestamo.');
return Reporte.create({ descripcion, idPrestamo });
return Reporte.create({ descripcion, idPrestamo, idEquipo });
})
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
};