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) => ({
|
||||
|
||||
+10
-3
@@ -7,6 +7,7 @@ const Area = require('./tablas/Area');
|
||||
const FechaInscripcion = require('./tablas/FechaInscripcion');
|
||||
const Inscripcion = require('./tablas/Inscripcion');
|
||||
const Admin = require('./tablas/Admin');
|
||||
const Impresion = require('./tablas/Impresion');
|
||||
|
||||
const drop = async () => {
|
||||
console.log('\nPaso 1) Desinstalando la db.'.bold.blue);
|
||||
@@ -23,11 +24,14 @@ const drop = async () => {
|
||||
await FechaInscripcion.drop();
|
||||
console.log('La tabla FechaInscripcion se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Usuario.drop();
|
||||
console.log('La tabla Usuario se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Carrera.drop();
|
||||
console.log('La tabla Carrera se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Impresion.drop();
|
||||
console.log('La tabla Impresion se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Usuario.drop();
|
||||
console.log('La tabla Usuario se desinstalo correctamente.'.magenta);
|
||||
};
|
||||
|
||||
const sync = async () => {
|
||||
@@ -42,6 +46,9 @@ const sync = async () => {
|
||||
await Usuario.sync();
|
||||
console.log('La tabla Usuario se instalo correctamente.'.magenta);
|
||||
|
||||
await Impresion.sync();
|
||||
console.log('La tabla Impresion se instalo correctamente.'.magenta);
|
||||
|
||||
await Area.sync();
|
||||
console.log('La tabla Area se instalo correctamente.'.magenta);
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Usuario = require('./Usuario');
|
||||
|
||||
class Impresion extends Model {}
|
||||
Impresion.init(
|
||||
{
|
||||
idImpresion: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
folio: {
|
||||
type: DataTypes.STRING(10),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
monto: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
fechaTicket: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Impresion',
|
||||
tableName: 'impresion',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
Impresion.belongsTo(Usuario, {
|
||||
foreignKey: {
|
||||
name: 'idUsuario',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
module.exports = Impresion;
|
||||
@@ -34,6 +34,11 @@ Usuario.init(
|
||||
type: DataTypes.STRING(60),
|
||||
allowNull: false,
|
||||
},
|
||||
credito: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
@@ -43,12 +48,12 @@ Usuario.init(
|
||||
}
|
||||
);
|
||||
|
||||
// Usuario.belongsTo(Carrera, {
|
||||
// foreignKey: {
|
||||
// name: 'idCarrera',
|
||||
// type: DataTypes.INTEGER,
|
||||
// allowNull: false,
|
||||
// },
|
||||
// });
|
||||
Usuario.belongsTo(Carrera, {
|
||||
foreignKey: {
|
||||
name: 'idCarrera',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Usuario;
|
||||
|
||||
@@ -37,10 +37,4 @@ const crearTokenAdmin = (data) => {
|
||||
});
|
||||
};
|
||||
|
||||
const crearTokenOperador = (data) => {
|
||||
return jwt.sign({ data }, process.env.KEY, {
|
||||
expiresIn: Number(process.env.CADUCIDAD_TOKEN_OPERADOR),
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { verificaToken, crearToken, crearTokenAdmin };
|
||||
|
||||
@@ -13,6 +13,9 @@ const motivo = require(`${controllerPath}/motivo`);
|
||||
const validarSinTicket = require(`${controllerPath}/validarSinTicket`);
|
||||
const validarTicket = require(`${controllerPath}/validarTicket`);
|
||||
const reporte = require(`${controllerPath}/reporte`);
|
||||
const restarCredito = require(`${controllerPath}/restarCredito`);
|
||||
const ticketsImpresion = require(`${controllerPath}/ticketsImpresion`);
|
||||
const credito = require(`${controllerPath}/credito`);
|
||||
|
||||
app.post(`${route}/login`, (req, res) => {
|
||||
return login(req.body)
|
||||
@@ -107,4 +110,34 @@ app.get(`${route}/reporte`, verificaToken, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/restar_credito`, verificaToken, (req, res) => {
|
||||
return restarCredito(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/tickets_impresion`, verificaToken, (req, res) => {
|
||||
return ticketsImpresion(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/credito`, verificaToken, (req, res) => {
|
||||
return credito(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -9,6 +9,8 @@ const controllerPath = '../controller/Usuario';
|
||||
const login = require(`${controllerPath}/login`);
|
||||
const inscripciones = require(`${controllerPath}/inscripciones`);
|
||||
const inscripcionUsuario = require(`${controllerPath}/inscripcionUsuario`);
|
||||
const agregarCredito = require(`${controllerPath}/agregarCredito`);
|
||||
const credito = require(`${controllerPath}/credito`);
|
||||
|
||||
app.post(`${route}/login`, (req, res) => {
|
||||
return login(req.body)
|
||||
@@ -45,4 +47,24 @@ app.post(
|
||||
}
|
||||
);
|
||||
|
||||
app.put(`${route}/agregar_credito`, (req, res) => {
|
||||
return agregarCredito(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/credito`, verificaToken, (req, res) => {
|
||||
return credito(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
numeroCuenta,idArea,folio,monto,hizoPago,fechaInscripcion,validacion,motivoDeclinacion
|
||||
419085500,1,123345,12,true,03/22/2022,0,prueba
|
||||
|
||||
|
Reference in New Issue
Block a user