const validar = require('../../helper/validar'); const Servicio = require('../../db/tablas/Servicio'); const Usuario = require('../../db/tablas/Usuario'); 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'); return Usuario.update({ activo: false }, { where: res.idUsuario }); }) .then((res) => { return Servicio.update({ idStatus: 10 }, { where: { idServicio } }); }) .then((res) => { return { message: 'Se cancelo correctamente este Servicio Social.' }; }); }; module.exports = cancelar;