80 lines
2.9 KiB
JavaScript
80 lines
2.9 KiB
JavaScript
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);
|
|
});
|
|
})
|
|
}
|
|
|
|
function twoDigits(d) {
|
|
if (0 <= d && d < 10) return "0" + d.toString();
|
|
if (-10 < d && d < 0) return "-0" + (-1 * d).toString();
|
|
return d.toString();
|
|
}
|
|
|
|
function dataJsToMysql(dat) {
|
|
console.log(dat);
|
|
console.log(dat.getUTCFullYear());
|
|
let ne = dat.getUTCFullYear() + "-" + twoDigits(1 + dat.getUTCMonth()) + "-" + twoDigits(dat.getUTCDate()) + " " + twoDigits(dat.getUTCHours()) + ":" + twoDigits(dat.getUTCMinutes()) + ":" + twoDigits(dat.getUTCSeconds());
|
|
console.log(ne);
|
|
return ne;
|
|
}
|
|
app.post('/datos_proyecto_2', async(req, res) => {
|
|
if (req.body.hipotesis == undefined || req.body.resumen == undefined || req.body.fecha_inicio == undefined ||
|
|
req.body.fecha_final == undefined || req.body.estado == undefined || req.body.duracion == undefined ||
|
|
req.body.id_proyecto == undefined || req.body.avance == undefined) {
|
|
console.log("No estan los datos que requiere la appi");
|
|
res.status(400).json({ error: true, msj: "No estan los datos que requiere la appi" });
|
|
return;
|
|
}
|
|
|
|
req.body.hipotesis = req.body.hipotesis.replace(/'/g, "''");
|
|
req.body.resumen = req.body.resumen.replace(/'/g, "''");
|
|
|
|
try {
|
|
|
|
console.log(req.body.fecha_inicio);
|
|
console.log(typeof(req.body.fecha_inicio));
|
|
let da = new Date(req.body.fecha_inicio);
|
|
console.log(da);
|
|
console.log(typeof(da));
|
|
|
|
|
|
|
|
let fecha_inicio = new Date(req.body.fecha_inicio);
|
|
let fecha_final = new Date(req.body.fecha_final);
|
|
let fecha_i = await dataJsToMysql(fecha_inicio);
|
|
let fecha_f = await dataJsToMysql(fecha_final);
|
|
|
|
console.log(typeof(fecha_i));
|
|
console.log(fecha_i);
|
|
console.log(fecha_f);
|
|
|
|
let cad = `update proyecto set hipotesis='${req.body.hipotesis}', resumen='${req.body.resumen}',
|
|
duracion='${req.body.duracion}', estado_avance='${req.body.estado}', avance=${req.body.avance},
|
|
fecha_inicio='${fecha_i}', fecha_final = '${fecha_f}'
|
|
where id_proyecto=${req.body.id_proyecto};`;
|
|
console.log(req.body.id_proyecto);
|
|
let respuesta = query(cad);
|
|
respuesta.catch(function(reason) {
|
|
console.log(reason);
|
|
res.status(400).json({ error: true, msj: 'Error al insertar en la base' });
|
|
return;
|
|
}).then(function(resp) {
|
|
//console.log(resp);
|
|
res.status(200).json({ error: false, msj: 'Exito al insertar' });
|
|
return;
|
|
})
|
|
} catch (error) {
|
|
res.status(400).json({ error: true, msj: 'Error al insertar en la base' });
|
|
return;
|
|
}
|
|
|
|
|
|
});
|
|
module.exports = app; |