32 lines
892 B
JavaScript
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;
|