Merge branch 'dev' of https://repositorio.acatlan.unam.mx/CIDWA/inscripciones_api into dev
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const { validarNumeroCuenta } = require('../../helper/validar');
|
||||
|
||||
const credito = async (body) => {
|
||||
const numeroCuenta = validarNumeroCuenta(
|
||||
body.numeroCuenta,
|
||||
'número de cuenta',
|
||||
true
|
||||
);
|
||||
return Usuario.findOne({
|
||||
where: { numeroCuenta },
|
||||
}).then(() => {
|
||||
return Usuario.findOne({
|
||||
attributes: ['credito', 'nombre', 'numeroCuenta'],
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = credito;
|
||||
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
@@ -0,0 +1,21 @@
|
||||
const { Op } = require('sequelize');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const Impresion = require(`${dbPath}/Impresion`);
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
|
||||
const ticketsImpresion = async (body) => {
|
||||
const validacion = validarNumeroEntero(body.validacion, 'validacion', true);
|
||||
return Impresion.findAll({
|
||||
where: { validacion },
|
||||
include: [
|
||||
{
|
||||
model: Usuario,
|
||||
where: { numeroCuenta: { [Op.like]: `%${body.numeroCuenta}%` } },
|
||||
attributes: ['idUsuario', 'numeroCuenta'],
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = ticketsImpresion;
|
||||
@@ -0,0 +1,64 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
const Impresion = require(`${dbPath}/Impresion`);
|
||||
const {
|
||||
validarNumeroEntero,
|
||||
validarNumeroCuenta,
|
||||
validarNumero,
|
||||
} = require('../../helper/validar');
|
||||
|
||||
const agregarCredito = async (body) => {
|
||||
const fechaTicket = body.fechaTicket;
|
||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'usuario', true);
|
||||
const monto = validarNumero(body.monto, 'monto', true);
|
||||
const folio = validarNumero(body.folio, 'folio', true, 6);
|
||||
const numeroCuenta = validarNumeroCuenta(
|
||||
body.numeroCuenta,
|
||||
'número de cuenta',
|
||||
true
|
||||
);
|
||||
|
||||
return Inscripcion.findOne({
|
||||
where: { folio, cancelacion: 0 },
|
||||
}).then((res) => {
|
||||
if (res)
|
||||
throw new Error('Este folio ya fue utilizado en alguna inscripción');
|
||||
return Impresion.findOne({
|
||||
where: { folio },
|
||||
})
|
||||
.then((res) => {
|
||||
if (res)
|
||||
throw new Error('Este folio ya fue utilizado para impresiones');
|
||||
return Usuario.findOne({ where: { numeroCuenta } }).then(() => {
|
||||
if (!res)
|
||||
throw new Error(
|
||||
'Lo sentimos no pudimos encontrar este número cuenta'
|
||||
);
|
||||
return Usuario.update(
|
||||
{
|
||||
credito: res.credito + creditoNuevo,
|
||||
},
|
||||
{
|
||||
where: { numeroCuenta },
|
||||
}
|
||||
).then((res) => {
|
||||
return Impresion.create({
|
||||
idUsuario,
|
||||
folio,
|
||||
monto,
|
||||
fechaTicket,
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
.then((res) => ({
|
||||
message: '¡Tu crédito se agrego correctamente!',
|
||||
}))
|
||||
.catch((err) => {
|
||||
throw new Error('¡ No fue posible agregar tu crédito !. ');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = agregarCredito;
|
||||
@@ -0,0 +1,20 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const { validarNumeroCuenta } = require('../../helper/validar');
|
||||
|
||||
const credito = async (body) => {
|
||||
const numeroCuenta = validarNumeroCuenta(
|
||||
body.numeroCuenta,
|
||||
'número de cuenta',
|
||||
true
|
||||
);
|
||||
return Usuario.findOne({
|
||||
where: { numeroCuenta },
|
||||
}).then(() => {
|
||||
return Usuario.findOne({
|
||||
attributes: ['credito'],
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = credito;
|
||||
@@ -68,14 +68,14 @@ const inscripcion = async (body, file) => {
|
||||
.then((res) => {
|
||||
if (file)
|
||||
fs.renameSync(file.path, file.path + '.' + file.mimetype.split('/')[1]);
|
||||
usuarioInscrito(numeroCuenta, idArea);
|
||||
agregarRecibo(
|
||||
folio,
|
||||
monto,
|
||||
moment(fechaTicket).format('L'),
|
||||
numeroCuenta
|
||||
);
|
||||
agregarDetalleServicio(monto, numeroCuenta);
|
||||
// usuarioInscrito(numeroCuenta, idArea);
|
||||
// agregarRecibo(
|
||||
// folio,
|
||||
// monto,
|
||||
// moment(fechaTicket).format('L'),
|
||||
// numeroCuenta
|
||||
// );
|
||||
// agregarDetalleServicio(monto, numeroCuenta);
|
||||
return gmail(correo.subject, email, correo.msj);
|
||||
})
|
||||
.then((res) => ({
|
||||
|
||||
Reference in New Issue
Block a user