termidado datos_rpoyecto_3
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
const connection = require('../conf/connection');
|
||||
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('/datos_proyecto_3', async(req, res) => {
|
||||
if (req.body.financiamiento == undefined || req.body.presupuesto == undefined || req.body.entidades == undefined ||
|
||||
req.body.producto == undefined || req.body.id_proyecto == undefined || req.body.no_registro == undefined) {
|
||||
res.status(400).json({ error: true, msj: "No estan los datos que requiere la appi" });
|
||||
return;
|
||||
|
||||
}
|
||||
try {
|
||||
let cad = `update proyecto set financiamiento="${req.body.financiamiento}", presupuesto=${req.body.presupuesto},
|
||||
numero_registro="${req.body.no_registro}" where id_proyecto=${req.body.id_proyecto};`
|
||||
let respuesta = query(cad);
|
||||
await respuesta.catch(function(reason) {
|
||||
console.log("entro al reason");
|
||||
console.log(reason);
|
||||
res.status(400).json({ error: true, msj: "Error al insertar en la base, proyecto" });
|
||||
return;
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(400).json({ error: true, msj: "Error al insertar en la base, proyecto-entidad" });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
await req.body.entidades.forEach(async element => {
|
||||
let cad = `insert into proyecto_entidad values (null, ${element[0]}, ${req.body.id_proyecto}, "${element[1]}");`
|
||||
let respuesta = query(cad);
|
||||
await respuesta.catch(function(reason) {
|
||||
console.log(reason);
|
||||
res.status(400).json({ error: true, msj: "Error al insertar en la base, proyecto-entidad" });
|
||||
return;
|
||||
})
|
||||
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(400).json({ error: true, msj: "Error al insertar en la base, proyecto-entidad" });
|
||||
return;
|
||||
}
|
||||
|
||||
// CREATE TABLE `proyecto_producto` (
|
||||
// `id_pro_producto` int PRIMARY KEY AUTO_INCREMENT,
|
||||
// `id_proyecto` int,
|
||||
// `id_producto` int
|
||||
// );
|
||||
try {
|
||||
let i = 1;
|
||||
await req.body.producto.forEach(async element => {
|
||||
console.log(element);
|
||||
console.log('\n');
|
||||
console.log('\n');
|
||||
let cad = `insert into proyecto_producto values (null, ${req.body.id_proyecto},${element});`;
|
||||
let respuesta = query(cad);
|
||||
await respuesta.catch(function(reason) {
|
||||
console.log(reason);
|
||||
res.status(400).json({ error: true, msj: "Error al insertar en la base, proyecto-producto" });
|
||||
return;
|
||||
})
|
||||
console.log(i);
|
||||
console.log(req.body.producto.length);
|
||||
if (i == req.body.producto.length) {
|
||||
res.status(200).json({ error: false, msj: "exito" });
|
||||
}
|
||||
i++;
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(400).json({ error: true, msj: "Error al insertar en la base, proyecto-entidad" });
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
module.exports = app;
|
||||
@@ -3,4 +3,5 @@ var app = express()
|
||||
app.use(require('./loggin'));
|
||||
app.use(require('./datos_proyecto_1'));
|
||||
app.use(require('./datos_proyecto_2'));
|
||||
app.use(require('./datos_proyecto_3'));
|
||||
module.exports = app;
|
||||
Reference in New Issue
Block a user