reporte y multa por numero de inventari
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Reporte = require(`${dbPath}/Reporte`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
|
||||
const reportar = async (body) => {
|
||||
const numeroInventario = validar.validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'El numero de inventario',
|
||||
20
|
||||
);
|
||||
const descripcion = validar.validarTexto(
|
||||
body.descripcion,
|
||||
'La descripción',
|
||||
500
|
||||
);
|
||||
let prestamo = {};
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { activo: true },
|
||||
include: [{ model: Equipo, where: { numeroInventario } }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res)
|
||||
throw new Error('No existe un prestamo activo con este equipo.');
|
||||
prestamo = res;
|
||||
return Reporte.findOne({ where: { idPrestamo: prestamo.idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Ya existe un reporte con este prestamo.');
|
||||
return Reporte.create({
|
||||
descripcion,
|
||||
idPrestamo: prestamo.idPrestamo,
|
||||
idEquipo: prestamo.idEquipo,
|
||||
});
|
||||
})
|
||||
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
|
||||
};
|
||||
|
||||
module.exports = reportar;
|
||||
Reference in New Issue
Block a user