44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
const connection = require('../conf/connection.js');
|
|
const express = require('express')
|
|
var app = express();
|
|
|
|
app.get('/cupo', async(req, res) => {
|
|
let arr = [];
|
|
connection.query(`Select * from conferencia;`, async(error, results, file) => {
|
|
if (error) {
|
|
res.status(400).json({ err: true });
|
|
return;
|
|
}
|
|
await results.forEach(async element => {
|
|
if (element.idConferencia == 7) {
|
|
await connection.query(`select count(asistencia) as asis from asistencia where idConferencia=7 and asistencia=1;`,
|
|
(e, r, f) => {
|
|
if (e) {
|
|
res.status(400).json({ err: true, msj: "error al contar" });
|
|
return;
|
|
}
|
|
arr.push([element.nombre, 'ilimitado', 100000 - element.capacidad, r[0].asis]);
|
|
})
|
|
|
|
} else {
|
|
await connection.query(`select count(asistencia) as asis from asistencia where idConferencia=${element.idConferencia} and asistencia=1;`,
|
|
(e, r, f) => {
|
|
if (e) {
|
|
res.status(400).json({ err: true, msj: "error al contar" });
|
|
return;
|
|
}
|
|
arr.push([element.nombre, 150, 150 - element.capacidad, r[0].asis]);
|
|
if (element.idConferencia == results.length) {
|
|
res.status(200).json(arr);
|
|
return;
|
|
}
|
|
})
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
});
|
|
|
|
|
|
module.exports = app; |