reportes
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
const { validarId, validarTexto } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Reporte = require(`${dbPath}/Reporte`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
|
||||
const reportar = async (body) => {
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
|
||||
|
||||
return Prestamo.findOne({ where: { idPrestamo } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
return Reporte.findOne({ where: { idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Ya existe un reporte con este prestamo.');
|
||||
return Reporte.create({ descripcion, idPrestamo });
|
||||
})
|
||||
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
|
||||
};
|
||||
|
||||
module.exports = reportar;
|
||||
@@ -0,0 +1,19 @@
|
||||
const { validarId, validarTexto } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Reporte = require(`${dbPath}/Reporte`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
|
||||
const reportar = async (body) => {
|
||||
console.log(body);
|
||||
const idEquipo = validarId(body.idEquipo);
|
||||
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
|
||||
|
||||
return Equipo.findOne({ where: { idEquipo } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este equipo.');
|
||||
return Reporte.create({ descripcion, idEquipo });
|
||||
})
|
||||
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
|
||||
};
|
||||
|
||||
module.exports = reportar;
|
||||
Reference in New Issue
Block a user