hisotrial reportes y mutlas
This commit is contained in:
@@ -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.' }));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user