Files
inscripciones_api/server/controller/Admin/restarCredito.js
T
2022-05-10 22:59:06 -05:00

32 lines
892 B
JavaScript

const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
const Inscripcion = require(`${dbPath}/Inscripcion`);
const Impresion = require(`${dbPath}/Impresion`);
const { validarNumeroCuenta, validarNumero } = require('../../helper/validar');
const restarCredito = async (body) => {
const creditoUsado = validarNumero(body.monto, 'monto', true);
const numeroCuenta = validarNumeroCuenta(
body.numeroCuenta,
'número de cuenta',
true
);
return Usuario.findOne({
where: { numeroCuenta },
}).then(() => {
if (!res) throw new Error('No encontramos este número de cuenta');
return Usuario.update(
{
credito: res.credito - creditoUsado,
},
{
where: { numeroCuenta },
}
).then((res) => ({
message: '¡La transaccion se realizo con éxito!',
}));
});
};
module.exports = restarCredito;