tabla motivo

This commit is contained in:
2022-03-21 20:48:29 -06:00
parent b33deda664
commit c04ca252df
6 changed files with 99 additions and 7 deletions
@@ -8,6 +8,7 @@ const Prestamo = require(`${dbPath}/Prestamo`);
const cancelarOperador = async (body) => {
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
const idOperador = validarNumeroEntero(body.idOperador, 'id operador', true);
const motivo = validar.validarAlfanumerico(body.motivo, 'motivo', true, 500);
let idUsuario = null;
return Operador.findOne({ where: { idOperador } })
@@ -15,15 +16,16 @@ const cancelarOperador = async (body) => {
if (!res) throw new Error('No existe este operador.');
return Prestamo.findOne({ where: { idPrestamo } });
})
.then((res) => {
.then(async (res) => {
if (!res) throw new Error('Este préstamo no existe.');
idUsuario = res.idUsuario;
if (!res.activo)
throw new Error(
'Este préstamo ya no esta activo, no se puede cancelar.'
);
await Motivo.create({ motivo, idEquipo: res.idEquipo, idStatus: 7 });
return Equipo.update(
{ idStatus: 4 },
{ idStatus: 7 },
{ where: { idEquipo: res.idEquipo } }
);
})