This commit is contained in:
KIKIN
2020-09-27 19:58:54 -05:00
11 changed files with 482 additions and 42 deletions
+21 -21
View File
@@ -190,29 +190,29 @@ async function exec() {
console.log(`\nFilling out ${ rows } records on equipo, printers and inventario. Please wait...\n`.cyan.italic.bold);
await fillingEquipo()
.then(() => {
console.log(symbols.success, `${ rows } records created on equipo.\n`.green.bold);
ok++;
})
.catch((e) => {
console.log(symbols.warning, 'Error creating «equipo».\n', e);
faileds++;
});
await fillingPrinters()
.then(() => {
console.log(symbols.success, `${ rows } records created on printers.\n`.green.bold);
ok++;
})
.catch((e) => {
console.log(symbols.warning, 'Error creating «printers».\n', e);
faileds++;
});
// await fillingEquipo()
// .then(() => {
// console.log(symbols.success, `${ rows } records created on equipo.\n`.green.bold);
// ok++;
// })
// .catch((e) => {
// console.log(symbols.warning, 'Error creating «equipo».\n', e);
// faileds++;
// });
// await fillingPrinters()
// .then(() => {
// console.log(symbols.success, `${ rows } records created on printers.\n`.green.bold);
// ok++;
// })
// .catch((e) => {
// console.log(symbols.warning, 'Error creating «printers».\n', e);
// faileds++;
// });
if (censo / 2 === rows) ok++;
else faileds++;
// if (censo / 2 === rows) ok++;
// else faileds++;
console.log(symbols.success, `${ censo } records added on inventario`.green.bold);
// console.log(symbols.success, `${ censo } records added on inventario`.green.bold);
console.log(`\n${ symbols.success }`, ` ${ ok } tables filled out succesfully.`.green.bold);
console.log(symbols.error, ` ${ faileds } tables wasn't filled out successfully.`.red.bold);
+100
View File
@@ -48,6 +48,15 @@
"negotiator": "0.6.2"
}
},
"adler-32": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.2.0.tgz",
"integrity": "sha1-aj5r8KY5ALoVZSgIyxXGgT0aXyU=",
"requires": {
"exit-on-epipe": "~1.0.1",
"printj": "~1.1.0"
}
},
"ansi-align": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.0.tgz",
@@ -275,6 +284,11 @@
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
"integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
},
"buffer-from": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"busboy": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz",
@@ -335,6 +349,16 @@
"redeyed": "~2.1.0"
}
},
"cfb": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.0.tgz",
"integrity": "sha512-sXMvHsKCICVR3Naq+J556K+ExBo9n50iKl6LGarlnvuA2035uMlGA/qVrc0wQtow5P1vJEw9UyrKLCbtIKz+TQ==",
"requires": {
"adler-32": "~1.2.0",
"crc-32": "~1.2.0",
"printj": "~1.1.2"
}
},
"chalk": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
@@ -459,6 +483,22 @@
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c="
},
"codepage": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/codepage/-/codepage-1.14.0.tgz",
"integrity": "sha1-jL4lSBMjVZ19MHVxsP/5HnodL5k=",
"requires": {
"commander": "~2.14.1",
"exit-on-epipe": "~1.0.1"
},
"dependencies": {
"commander": {
"version": "2.14.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw=="
}
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
@@ -477,6 +517,11 @@
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
},
"commander": {
"version": "2.17.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz",
"integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg=="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -538,6 +583,15 @@
"vary": "^1"
}
},
"crc-32": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.0.tgz",
"integrity": "sha512-1uBwHxF+Y/4yF5G48fwnKq6QsIXheor3ZLPT80yGBV1oEUwpPojlEhQbWKVw1VwcTQyMGHK1/XMmTjmlsmTTGA==",
"requires": {
"exit-on-epipe": "~1.0.1",
"printj": "~1.1.0"
}
},
"crypto-random-string": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz",
@@ -684,6 +738,11 @@
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
},
"exit-on-epipe": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz",
"integrity": "sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw=="
},
"express": {
"version": "4.17.1",
"resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz",
@@ -793,6 +852,11 @@
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
},
"frac": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz",
"integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA=="
},
"fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
@@ -1521,6 +1585,15 @@
"tar": "^4.4.2"
}
},
"node-xlsx": {
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/node-xlsx/-/node-xlsx-0.15.0.tgz",
"integrity": "sha512-rQyhWDJ/k60wQemov7a8MlToastWTidrAVFRwTWV+s53LN/SRwU4lnmc5xuFXx/ay+uaLAsAQBp6BkVob5OjOA==",
"requires": {
"buffer-from": "^1.1.0",
"xlsx": "^0.14.1"
}
},
"nodemailer": {
"version": "6.4.11",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.4.11.tgz",
@@ -1706,6 +1779,11 @@
"integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=",
"dev": true
},
"printj": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/printj/-/printj-1.1.2.tgz",
"integrity": "sha512-zA2SmoLaxZyArQTOPj5LXecR+RagfPSU5Kw1qP+jkWeNlrq+eJZyY2oS68SU1Z/7/myXM4lo9716laOFAVStCQ=="
},
"process-nextick-args": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
@@ -2021,6 +2099,14 @@
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.2.tgz",
"integrity": "sha512-vF4ZbYdKS8OnoJAWBmMxCQDkiEBkGQYU7UZPtL8flbDRSNkhaXvRJ279ZtI6M+zDaQovVU4tuRgzK5fVhvFAhg=="
},
"ssf": {
"version": "0.10.3",
"resolved": "https://registry.npmjs.org/ssf/-/ssf-0.10.3.tgz",
"integrity": "sha512-pRuUdW0WwyB2doSqqjWyzwCD6PkfxpHAHdZp39K3dp/Hq7f+xfMwNAWIi16DyrRg4gg9c/RvLYkJTSawTPTm1w==",
"requires": {
"frac": "~1.1.2"
}
},
"statuses": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
@@ -2343,6 +2429,20 @@
"integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==",
"dev": true
},
"xlsx": {
"version": "0.14.5",
"resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.14.5.tgz",
"integrity": "sha512-s/5f4/mjeWREmIWZ+HtDfh/rnz51ar+dZ4LWKZU3u9VBx2zLdSIWTdXgoa52/pnZ9Oe/Vu1W1qzcKzLVe+lq4w==",
"requires": {
"adler-32": "~1.2.0",
"cfb": "^1.1.2",
"codepage": "~1.14.0",
"commander": "~2.17.1",
"crc-32": "~1.2.0",
"exit-on-epipe": "~1.0.1",
"ssf": "~0.10.2"
}
},
"yallist": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
+1
View File
@@ -25,6 +25,7 @@
"moment": "^2.27.0",
"mysql2": "^2.1.0",
"node-localstorage": "^2.1.6",
"node-xlsx": "^0.15.0",
"sequelize": "^6.3.4"
},
"devDependencies": {
+4 -4
View File
@@ -6,17 +6,17 @@ let app = express();
let config = require("./config/config.js");
app.use(cors());
app.get("/", function (req, res) {
res.send("Servicio activo");
app.get("/", function(req, res) {
res.send("Servicio activo");
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(
bodyParser.json()
bodyParser.json()
);
app.use(require('./routes/index'))
app.listen(process.env.PORT, function () {
app.listen(process.env.PORT, function() {
console.log(`Censo 2020 corriendo en puerto ${process.env.PORT}`)
});
View File
+183
View File
@@ -0,0 +1,183 @@
const xlsx = require('node-xlsx');
const UResponsable = require('../../models/tablas/UResponsable');
const Ubicacion = require('../../models/tablas/Ubicacion');
const Uso = require('../../models/tablas/Uso');
const ActivoFijo = require('../../models/tablas/ActivoFijo');
const OS = require('../../models/tablas/OS');
const Marca = require('../../models/tablas/Marca');
const Inventario = require('../../models/tablas/Inventario');
const Equipo = require('../../models/tablas/Equipo');
const post = async(req, res) => {
const file = req.files.equipos;
let equipos = [];
let ubicaciones = [];
let unidades = [];
let usos = [];
let activos = [];
let os = [];
let marcas = [];
await Ubicacion.findAll({
attributes: ['ubicacion'],
order: ['idUbicacion']
})
.then(resultado => {
resultado.forEach(el => ubicaciones.push(Object.entries(el.dataValues)));
resultado = ubicaciones.flat(2);
ubicaciones = resultado.filter(ubicacion => ubicacion != 'ubicacion')
})
.catch(err => res.status(500).json({
ok: false,
error: err
}));
await UResponsable.findAll({
attributes: ['uResponsable'],
order: ['idUnidadResponsable']
})
.then((result) => {
result.forEach(el => unidades.push(Object.entries(el.dataValues)));
unidades = unidades.flat(2);
unidades = unidades.filter(filtro => filtro != 'uResponsable')
}).catch((err) => res.status(500).json({
ok: false,
error: err
}));
await Uso.findAll({
attributes: ['uso'],
order: ['idUso']
})
.then((result) => {
result.forEach(el => usos.push(Object.entries(el.dataValues)));
usos = usos.flat(2);
usos = usos.filter(filtro => filtro != 'uso')
}).catch((err) => res.status(500).json({
ok: false,
error: err
}));
await ActivoFijo.findAll({
attributes: ['activoFijo'],
order: ['idActivoFijo']
})
.then((result) => {
result.forEach(el => activos.push(Object.entries(el.dataValues)));
activos = activos.flat(2);
activos = activos.filter(filtro => filtro != 'activoFijo')
}).catch((err) => res.status(500).json({
ok: false,
error: err
}));
await OS.findAll({
attributes: ['osname'],
order: ['idOS']
})
.then((result) => {
result.forEach(el => os.push(Object.entries(el.dataValues)));
os = os.flat(2);
os = os.filter(filtro => filtro != 'osname')
}).catch((err) => res.status(500).json({
ok: false,
error: err
}));
await Marca.findAll({
attributes: ['marca'],
order: ['idMarca']
})
.then((result) => {
result.forEach(el => marcas.push(Object.entries(el.dataValues)));
marcas = marcas.flat(2);
marcas = marcas.filter(filtro => filtro != 'marca')
}).catch((err) => res.status(500).json({
ok: false,
error: err
}));
let data = await xlsx.parse(file.tempFilePath);
data = Object.entries(data[0]);
data.shift();
data = data[0][1]
data.shift();
data.forEach(row => {
let equipo = {
noInventario: row[0],
activoFijo: activos.indexOf(row[1]) + 1,
modelo: row[2],
marca: marcas.indexOf(row[3]) + 1,
noSerie: row[4],
procesador: row[5],
vProcesador: row[6],
hdd: row[7],
memoriasz: row[8],
memoria: row[9],
vMemoria: row[10],
graficos: row[11],
osname: os.indexOf(row[12]) + 1,
noResguardo: row[13],
uResponsable: unidades.indexOf(row[14]) + 1,
ubicacion: ubicaciones.indexOf(row[16]) + 1,
uso: usos.indexOf(row[17]) + 1,
}
equipos.push(equipo);
});
let count = 0;
for (equipo of equipos) {
count++;
await Inventario.create({
noInventario: equipo.noInventario,
noResguardo: equipo.noResguardo,
idActivoFijo: equipo.activoFijo,
idUnidadResponsable: equipo.uResponsable,
idUbicacion: equipo.ubicacion,
idUso: equipo.uso
})
.then(async() => {
await Equipo.create({
noInventario: equipo.noInventario,
idActivoFijo: equipo.activoFijo,
idMarca: equipo.marca,
idOS: equipo.osname,
modelo: equipo.modelo,
noSerie: equipo.noSerie,
procesador: equipo.procesador,
vProcesador: equipo.vProcesador,
memoria: equipo.memoria,
vMemoria: equipo.vMemoria,
memoriasz: equipo.memoriasz,
graficos: equipo.graficos,
hdd: equipo.hdd
})
.catch(async(err) => {
await Inventario.destroy({
where: {
noInventario: equipo.noInventario
}
});
return res.status(500).json({
ok: false,
err
})
})
})
.catch((e) => res.status(500).json({
ok: false,
e
}))
}
res.json({
ok: true,
message: `${ count } records created successfully.`
})
}
module.exports = post
+154
View File
@@ -0,0 +1,154 @@
const xlsx = require('node-xlsx');
const UResponsable = require('../../models/tablas/UResponsable');
const Ubicacion = require('../../models/tablas/Ubicacion');
const Uso = require('../../models/tablas/Uso');
const Marca = require('../../models/tablas/Marca');
const Tipo = require('../../models/tablas/Tipo');
const Inventario = require('../../models/tablas/Inventario');
const Printers = require('../../models/tablas/Printers');
const post = async(req, res) => {
const file = req.files.printers;
let printers = [];
let ubicaciones = [];
let unidades = [];
let usos = [];
let tipos = [];
let marcas = [];
await Ubicacion.findAll({
attributes: ['ubicacion'],
order: ['idUbicacion']
})
.then(resultado => {
resultado.forEach(el => ubicaciones.push(Object.entries(el.dataValues)));
resultado = ubicaciones.flat(2);
ubicaciones = resultado.filter(ubicacion => ubicacion != 'ubicacion')
})
.catch(err => res.status(500).json({
ok: false,
error: err
}));
await UResponsable.findAll({
attributes: ['uResponsable'],
order: ['idUnidadResponsable']
})
.then((result) => {
result.forEach(el => unidades.push(Object.entries(el.dataValues)));
unidades = unidades.flat(2);
unidades = unidades.filter(filtro => filtro != 'uResponsable')
}).catch((err) => res.status(500).json({
ok: false,
error: err
}));
await Uso.findAll({
attributes: ['uso'],
order: ['idUso']
})
.then((result) => {
result.forEach(el => usos.push(Object.entries(el.dataValues)));
usos = usos.flat(2);
usos = usos.filter(filtro => filtro != 'uso')
}).catch((err) => res.status(500).json({
ok: false,
error: err
}));
await Marca.findAll({
attributes: ['marca'],
order: ['idMarca']
})
.then((result) => {
result.forEach(el => marcas.push(Object.entries(el.dataValues)));
marcas = marcas.flat(2);
marcas = marcas.filter(filtro => filtro != 'marca')
}).catch((err) => res.status(500).json({
ok: false,
error: err
}));
await Tipo.findAll({
attributes: ['tipo'],
order: ['idTipo']
})
.then((result) => {
result.forEach(el => tipos.push(Object.entries(el.dataValues)));
tipos = tipos.flat(2);
tipos = tipos.filter(filtro => filtro != 'tipo')
}).catch((err) => res.status(500).json({
ok: false,
error: err
}));
let data = await xlsx.parse(file.tempFilePath);
data = Object.entries(data[0]);
data.shift();
data = data[0][1]
data.shift();
data.forEach(row => {
let printer = {
noInventario: row[0],
idTipo: tipos.indexOf(row[1]) + 1,
modelo: row[2],
idMarca: marcas.indexOf(row[3]) + 1,
noSerie: row[4],
descripcion: row[5],
idActivoFijo: 6,
noResguardo: row[6],
idUnidadResponsable: unidades.indexOf(row[7]) + 1,
idUbicacion: ubicaciones.indexOf(row[9]) + 1,
idUso: usos.indexOf(row[10]) + 1
}
printers.push(printer);
});
let count = 0;
for (printer of printers) {
count++;
await Inventario.create({
noInventario: printer.noInventario,
noResguardo: printer.noResguardo,
idActivoFijo: 6,
idUnidadResponsable: printer.idUnidadResponsable,
idUbicacion: printer.idUbicacion,
idUso: printer.idUso
})
.then(async() => {
await Printers.create({
noInventario: printer.noInventario,
idMarca: printer.idMarca,
modelo: printer.modelo,
noSerie: printer.noSerie,
idTipo: printer.idTipo,
descripcion: printer.descripcion,
idActivoFijo: 6
})
.catch(async(err) => {
await Inventario.destroy({
where: {
noInventario: printer.noInventario
}
});
return res.status(500).json({
ok: false,
err
})
})
})
.catch((e) => res.status(500).json({
ok: false,
e
}))
}
res.json({
ok: true,
message: `${ count } records created successfully.`
})
}
module.exports = post
+4 -6
View File
@@ -9,7 +9,7 @@ const get = async(req, res) => {
// });
//console.log(req["tipo"].value);
await sequelize.query(`
SELECT I.noInventario, AF.activoFijo, E.modelo, M.marca, E.noSerie, E.procesador, E.hdd, E.memoriasz, E.memoria, E.vMemoria, E.graficos, OS.osname, UR.uResponsable, UR.nombreResponsable, Ub.ubicacion, U.uso, I.noResguardo
SELECT I.noInventario, AF.activoFijo, E.modelo, M.marca, E.noSerie, E.procesador, E.vProcesador, E.hdd, E.memoriasz, E.memoria, E.vMemoria, E.graficos, OS.osname, I.noResguardo, UR.uResponsable, UR.nombreResponsable, Ub.ubicacion, U.uso
FROM inventario I
INNER JOIN activoFijo AF ON AF.idActivoFijo = I.idActivoFijo
INNER JOIN equipo E ON E.noInventario = I.noInventario
@@ -19,11 +19,9 @@ const get = async(req, res) => {
INNER JOIN ubicacion Ub ON Ub.idUbicacion = I.idUbicacion
INNER JOIN uso U ON U.idUso = I.idUso
ORDER BY E.createdAt DESC`, { type: QueryTypes.SELECT })
.then(equipo => {
return res.json({
equipo
})
})
.then(equipo => res.json({
equipo
}))
.catch(error => res.status(500).json({
error
}));
+4 -1
View File
@@ -5,11 +5,14 @@ const { QueryTypes } = require('sequelize');
const get = async(req, res) => {
await sequelize.query(`
SELECT I.noInventario, T.tipo, P.modelo, M.marca, P.noSerie, P. descripcion
SELECT I.noInventario, T.tipo, P.modelo, M.marca, P.noSerie, P. descripcion, I.noResguardo, UR.uResponsable, UR.nombreResponsable, Ub.ubicacion, U.uso
FROM inventario I
INNER JOIN printers P ON P.noInventario = I.noInventario
INNER JOIN marca M ON M.idMarca = P.idMarca
INNER JOIN tipo T ON T.idTipo = P.idTipo
INNER JOIN uResponsable UR ON UR.idUnidadResponsable = I.idUnidadResponsable
INNER JOIN ubicacion Ub ON Ub.idUbicacion = I.idUbicacion
INNER JOIN uso U ON U.idUso = I.idUso
ORDER BY P.createdAt DESC
`, { type: QueryTypes.SELECT })
.then(printers => {
+1
View File
@@ -7,5 +7,6 @@ app.use(require('./addEquip'));
app.use(require('./addPrinter'));
app.use(require('./updateEquip'));
app.use(require('./updatePrinter'));
app.use(require('./upload'));
module.exports = app;
+10 -10
View File
@@ -1,23 +1,23 @@
const express = require("express");
const fileUpload = require("express-fileupload");
const post = require("../controller/upload/post");
const postE = require("../controller/upload/postE");
const postP = require("../controller/upload/postP");
const app = express();
const { verifyToken, verifyAdmin } = require('../middlewares/authentication');
const route = "/upload";
// app.use(fileUpload({ createParentPath: true }));
app.use(fileUpload({ useTempFiles: true }));
app.post(route, verifyToken, (req, res) => {
return post(req)
.then(data => {
res.status(200).json(data);
})
.catch(err => {
res.status(400).json({ err: err.message });
});
app.post(`${ route }/equips`, (req, res) => {
return postE(req, res);
});
module.exports = app;
app.post(`${ route }/printers`, (req, res) => {
return postP(req, res);
});
module.exports = app;