multa por usuario
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Multa = require(`${dbPath}/Multa`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const multar = async (body) => {
|
||||
const idUsuario = validar.validarNumeroEntero(
|
||||
body.idUsuario,
|
||||
'id usuario',
|
||||
true
|
||||
);
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
return Multa.findAll({ where: { idUsuario, activo: true } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.length > 2)
|
||||
throw new Error(
|
||||
'El usuario tiene más de 2 multas activas, favor de notificar a un operador sobre este problema.'
|
||||
);
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = multar;
|
||||
Reference in New Issue
Block a user