Merge branch 'alima' into dev

This commit is contained in:
2020-10-10 15:35:17 -05:00
5 changed files with 63 additions and 89 deletions
+6 -6
View File
@@ -22,12 +22,12 @@ const post = async(req, res) => {
data.shift();
for (row of data) {
if (row[1]) {
var activoFijo = await ActivoFijo.findOrCreate({
var activoFijo = await ActivoFijo.findOne({
where: {
activoFijo: row[1] || 'No declarado'
}
})
.catch((res) => console.log(res));
.catch((e) => { throw new Error(e); });
}
if (row[3]) {
@@ -49,7 +49,7 @@ const post = async(req, res) => {
}
if (row[14]) {
var uResponsable = await UResponsable.findOrCreate({
var uResponsable = await UResponsable.findOne({
where: {
uResponsable: row[14] || 'No declarado'
}
@@ -77,7 +77,7 @@ const post = async(req, res) => {
let equipo = {
noInventario: row[0],
idActivoFijo: activoFijo[0]['idActivoFijo'],
idActivoFijo: activoFijo.dataValues.idActivoFijo,
modelo: row[2],
marca: marca[0]['idMarca'],
noSerie: row[4],
@@ -90,7 +90,7 @@ const post = async(req, res) => {
graficos: row[11],
osname: os[0]['idOS'],
noResguardo: row[13],
uResponsable: uResponsable[0]['idUnidadResponsable'],
uResponsable: uResponsable.dataValues.idUnidadResponsable,
ubicacion: ubicacion[0]['idUbicacion'],
uso: uso[0]['idUso']
}
@@ -112,7 +112,7 @@ const post = async(req, res) => {
.then(async() => {
await Equipo.create({
noInventario: equipo.noInventario,
idActivoFijo: equipo.activoFijo,
idActivoFijo: equipo.idActivoFijo,
idMarca: equipo.marca,
idOS: equipo.osname,
modelo: equipo.modelo,
+54 -80
View File
@@ -12,106 +12,80 @@ 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 => {
for (row of data) {
if (row[1]) {
var tipo = await Tipo.findOrCreate({
where: {
tipo: row[1] || 'No declarado'
}
})
.catch((e) => { throw new Error(e); });
}
if (row[3]) {
var marca = await Marca.findOrCreate({
where: {
marca: row[3] || 'No declarado'
}
})
.catch((e) => { throw new Error(e); });
}
if (row[7]) {
var uResponsable = await UResponsable.findOne({
where: {
uResponsable: row[7] || 'No declarado'
}
})
.catch((e) => { throw new Error(e); });
}
if (row[9]) {
var ubicacion = await Ubicacion.findOrCreate({
where: {
ubicacion: row[9] || 'No declarado'
}
})
.catch((e) => { throw new Error(e); });
}
if (row[10]) {
var uso = await Uso.findOrCreate({
where: {
uso: row[10] || 'No declarado'
}
})
.catch((e) => { throw new Error(e); });
}
let printer = {
noInventario: row[0],
idTipo: tipos.indexOf(row[1]) + 1,
idTipo: tipo[0]['idTipo'],
modelo: row[2],
idMarca: marcas.indexOf(row[3]) + 1,
idMarca: marca[0]['idMarca'],
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
idUnidadResponsable: uResponsable.dataValues.idUnidadResponsable,
idUbicacion: ubicacion[0]['idUbicacion'],
idUso: uso[0]['idUso']
}
printers.push(printer);
});
};
let count = 0;
for (printer of printers) {
count++;
await Inventario.create({
noInventario: printer.noInventario,
noResguardo: printer.noResguardo,
idActivoFijo: 6,
idActivoFijo: printer.idActivoFijo,
idUnidadResponsable: printer.idUnidadResponsable,
idUbicacion: printer.idUbicacion,
idUso: printer.idUso
@@ -124,7 +98,7 @@ const post = async(req, res) => {
noSerie: printer.noSerie,
idTipo: printer.idTipo,
descripcion: printer.descripcion,
idActivoFijo: 6
idActivoFijo: printer.idActivoFijo
})
.catch(async(err) => {
await Inventario.destroy({
+1 -1
View File
@@ -18,7 +18,7 @@ const get = async(req, res) => {
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 E.createdAt DESC`, { type: QueryTypes.SELECT })
ORDER BY E.noInventario ASC`, { type: QueryTypes.SELECT })
.then(equipo => res.json({
equipo
}))
+1 -1
View File
@@ -13,7 +13,7 @@ const get = async(req, res) => {
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
ORDER BY P.noInventario ASC
`, { type: QueryTypes.SELECT })
.then(printers => {
return res.json({