Merge branch 'dev' of https://repositorio.acatlan.unam.mx/CIDWA/censo2020Back into dev
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
}));
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user