Files
servicio_social_api/server/controller/Servicio/cancelar.js
T

24 lines
792 B
JavaScript
Raw Normal View History

2020-11-22 19:27:29 -06:00
const validar = require('../../helper/validar');
const Servicio = require('../../db/tablas/Servicio');
2020-11-23 12:56:24 -06:00
const Usuario = require('../../db/tablas/Usuario');
2020-11-22 19:27:29 -06:00
const cancelar = async (body) => {
let idServicio = validar.validarId(body.idServicio);
return Servicio.findOne({ where: { idServicio } })
.then((res) => {
if (!res) throw new Error('No existe este servicio.');
if (res.idStatus === 10)
throw new Error('Este servicio ya fue cancelado');
2020-11-23 12:56:24 -06:00
return Usuario.update({ activo: false }, { where: res.idUsuario });
})
.then((res) => {
2020-11-22 19:27:29 -06:00
return Servicio.update({ idStatus: 10 }, { where: { idServicio } });
})
.then((res) => {
2020-11-23 11:03:30 -06:00
return { message: 'Se cancelo correctamente este Servicio Social.' };
2020-11-22 19:27:29 -06:00
});
};
module.exports = cancelar;