Validacion del ticket

This commit is contained in:
Andres2908
2022-02-04 01:08:23 -06:00
parent 0710ee28ee
commit 7a10077bfe
2 changed files with 48 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
const dbPath = '../../db/tablas';
const Inscripcion = require(`${dbPath}/Inscripcion`);
const validarTicket = async (body) => {
console.log(body);
return Inscripcion.findOne({
where: { folio: body.folio },
})
.then((res) => {
if (!res) throw new Error('Este folio no existe');
return Inscripcion.update(
{
validacion: body.validacion,
},
{
where: {
folio: body.folio,
},
}
);
})
.then((res) => {
console.log(body.validacion);
if (body.validacion === false)
throw new Error('El administrador a declinado el ticket');
})
.then((res) => ({
message: '¡ El ticket a sido validado de forma correcta !',
}))
.catch((err) => {
throw new Error('No fue posible validar el ticekt. ' + err);
});
};
module.exports = validarTicket;
+13 -1
View File
@@ -1,10 +1,12 @@
const express = require('express');
const ticket = require('../controller/Admin/ticket');
const app = express();
const fs = require('fs');
const { validarAlfanumerico } = require('../helper/validar');
const route = '/Admin';
const controllerPath = '../controller/Admin';
const todasInscripciones = require(`${controllerPath}/todasInscripciones`);
const ticket = require(`${controllerPath}/ticket`);
const validarTicket = require(`${controllerPath}/validarTicket`);
app.get(`${route}/todas_inscripciones`, (req, res) => {
return todasInscripciones(req.query)
@@ -28,4 +30,14 @@ app.get(`${route}/ticket`, (req, res) => {
});
});
app.put(`${route}/validar`, (req, res) => {
return validarTicket(req.body)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
module.exports = app;