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
+9 -1
View File
@@ -2,6 +2,7 @@ const validar = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrito = require(`${dbPath}/Carrito`);
const Equipo = require(`${dbPath}/Equipo`);
const Motivo = require(`${dbPath}/Motivo`);
const Programa = require(`${dbPath}/Programa`);
const Status = require(`${dbPath}/Status`);
@@ -20,14 +21,20 @@ const update = async (body) => {
const idPrograma = body.idPrograma
? validar.validarNumeroEntero(body.idPrograma, 'id programa', true)
: '';
const motivo = body.motivo
? validar.validarAlfanumerico(body.motivo, 'motivo', true, 500)
: '';
let update = {};
return Status.findOne({ where: { idStatus } })
.then((res) => {
if (idStatus) {
if (!res) throw new Error('No existe este status.');
if (idStatus >= 6 && !motivo)
throw new Error('No se mando el motivo de cambio de status.');
update.idStatus = idStatus;
}
return Carrito.findOne({ where: { idCarrito } });
})
.then((res) => {
@@ -46,8 +53,9 @@ const update = async (body) => {
throw new Error('No se envió nada para actualizar.');
return Equipo.findOne({ where: { idEquipo } });
})
.then((res) => {
.then(async (res) => {
if (!res) throw new Error('No existe este equipo.');
if (idStatus >= 6) await Motivo.create({ motivo, idEquipo, idStatus });
return Equipo.update(update, { where: { idEquipo } });
})
.then(() => ({ message: 'Se actualizó correctamente el equipo.' }));