85 lines
3.0 KiB
JavaScript
85 lines
3.0 KiB
JavaScript
const connection = require('../conf/connection.js');
|
|
const express = require('express');
|
|
|
|
|
|
var app = express()
|
|
|
|
function query(consulta) {
|
|
return new Promise(function(resolve, reject) {
|
|
connection.query(`${consulta}`, (error, results, files) => {
|
|
if (error) reject(error);
|
|
resolve(results);
|
|
});
|
|
})
|
|
}
|
|
|
|
|
|
|
|
app.post('/registro_evento', async(req, res) => {
|
|
try {
|
|
console.log(req.body);
|
|
let datos=req.body.eventos;
|
|
let id_persona= req.body.id_persona;
|
|
let pag=true;
|
|
let con=req.body.constancia;
|
|
let total= req.body.total_pago;
|
|
|
|
let eliminar_eventos=`select distinct f.id_evento from fecha as f inner join asistencia as a where a.id_persona=${id_persona} and a.id_fecha=f.id_fecha `;
|
|
let query_eliminar= await query(eliminar_eventos);
|
|
//console.log(query_eliminar);
|
|
|
|
for(let i=0; i<query_eliminar.length; i++)
|
|
{
|
|
let nueva_cad =`update evento set cupo=cupo+1 where id_evento=${query_eliminar[i].id_evento};`;
|
|
let agregar=await query(nueva_cad);
|
|
}
|
|
eliminar_eventos=`delete from asistencia where id_persona=${id_persona};`;
|
|
query_eliminar=await query(eliminar_eventos);
|
|
eliminar_eventos = `delete from pago where id_persona=${id_persona};`;
|
|
query_eliminar=await query(eliminar_eventos);
|
|
|
|
|
|
|
|
if(con==true)
|
|
pag=false;
|
|
for(let i=0;i<datos.length; i++)
|
|
{
|
|
//console.log(datos[i]);
|
|
let nueva_cad =`update evento set cupo=cupo-1 where id_evento=${datos[i].id_evento};`;
|
|
let nueva_query=await query(nueva_cad);
|
|
let n_cad=`select * from fecha where id_evento=${datos[i].id_evento};`;
|
|
|
|
let n_ans=await query(n_cad);
|
|
// console.log(n_ans);
|
|
for(let j=0; j<n_ans.length; j++)
|
|
{
|
|
if(datos[i].tipo_evento=="Ponencia")
|
|
{
|
|
let ins_cad=`insert into asistencia values(null, ${id_persona}, ${n_ans[j].id_fecha}, false, true, false);`;
|
|
let ins_query= await query(ins_cad);
|
|
}
|
|
if(datos[i].tipo_evento=="Taller")
|
|
{
|
|
let ins_cad=`insert into asistencia values(null, ${id_persona}, ${n_ans[j].id_fecha}, true, false, false);`;
|
|
let ins_query= await query(ins_cad);
|
|
}
|
|
if(datos[i].tipo_evento=="Mesa tematica")
|
|
{
|
|
let ins_cad=`insert into asistencia values(null, ${id_persona}, ${n_ans[j].id_fecha}, ${con}, ${pag}, false);`;
|
|
let ins_query= await query(ins_cad);
|
|
}
|
|
|
|
}
|
|
}
|
|
let cad=`insert into pago values (null, ${id_persona}, ${total});`;
|
|
let nueva_query= await query(cad);
|
|
res.status(200).json({error: false, msj: "exito"});
|
|
|
|
} catch (err) {
|
|
console.log("afuera ", err);
|
|
res.status(400).json({ error: true, msj: err });
|
|
}
|
|
|
|
});
|
|
|
|
module.exports = app |