56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
const connection = require('../conf/connection.js');
|
|
const express = require('express')
|
|
|
|
var app = express()
|
|
|
|
app.post('/registro', async(req, res) => {
|
|
let body = req.body;
|
|
|
|
await body.alta.forEach(element => {
|
|
connection.query(`Select capacidad from conferencia where idConferencia=${element};`,
|
|
(error, results, fields) => {
|
|
if (error) {
|
|
res.status(400).json({ msj: `Error al actualizar la asistencia` });
|
|
throw error;
|
|
}
|
|
if (results[0].capacidad < 1) {
|
|
res.status(400).json({ msj: `Capacidad llena de la conferencia ${element}` });
|
|
throw error;
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
await body.alta.forEach(element => {
|
|
connection.query(`INSERT INTO asistencia VALUES(null,${element},${body.idPersona},false)`,
|
|
(error, results, fields) => {
|
|
if (error) {
|
|
res.status(400).json({ msj: `Error al actualizar la asistencia` });
|
|
throw error;
|
|
}
|
|
|
|
});
|
|
|
|
connection.query(`update conferencia set capacidad=capacidad-1 where idConferencia=${element};`,
|
|
function(error, results, fields) {
|
|
if (error) {
|
|
res.status(400).json({ err: true, msj: 'Error en la actualizacion de asistencia' });
|
|
throw error;
|
|
}
|
|
});
|
|
});
|
|
|
|
await body.baja.forEach(element => {
|
|
connection.query(`delete from asistencia where idConferencia=${element} and idPersona=${body.idPersona};`,
|
|
(error, results, fields) => {
|
|
if (error) {
|
|
res.status(400).json({ msj: `Error al actualizar eliminar la asistencia` });
|
|
throw error;
|
|
}
|
|
|
|
});
|
|
});
|
|
await res.status(200).json({ err: false, msj: 'exito' });
|
|
});
|
|
|
|
module.exports = app |