cancelar servicio

This commit is contained in:
2020-11-22 19:27:29 -06:00
parent e9a29d6d81
commit dd1d6f779e
4 changed files with 35 additions and 4 deletions
+19
View File
@@ -0,0 +1,19 @@
const validar = require('../../helper/validar');
const Servicio = require('../../db/tablas/Servicio');
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 Servicio.update({ idStatus: 10 }, { where: { idServicio } });
})
.then((res) => {
return { message: 'Se cancelo correctamente el servicio.' };
});
};
module.exports = cancelar;
+2 -2
View File
@@ -16,9 +16,9 @@ const serviciosAdmin = async (body) => {
let numeroCuenta = body.numeroCuenta
? validar.validarNumeroCuenta(body.numeroCuenta)
: '';
let where = {};
let where = { [Op.and]: [{ idStatus: { [Op.ne]: 10 } }] };
if (idStatus) where.idStatus = idStatus;
if (idStatus) where[Op.and].push({ idStatus });
return Usuario.findOne({ where: { idUsuario } })
.then((res) => {
if (!res) throw new Error('No existe este usuario.');
@@ -17,9 +17,9 @@ const serviciosResponsable = async (body) => {
let numeroCuenta = body.numeroCuenta
? validar.validarNumeroCuenta(body.numeroCuenta)
: '';
let where = {};
let where = { [Op.and]: [{ idStatus: { [Op.ne]: 10 } }] };
if (idStatus) where.idStatus = idStatus;
if (idStatus) where[Op.and].push({ idStatus });
return Usuario.findOne({ where: { idUsuario } })
.then((res) => {
if (!res) throw new Error('No existe este usuario.');