Merge branch 'alima' into dev
This commit is contained in:
@@ -14,103 +14,72 @@ 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 => {
|
||||
for (row of data) {
|
||||
if (row[1]) {
|
||||
var activoFijo = await ActivoFijo.findOrCreate({
|
||||
where: {
|
||||
activoFijo: row[1] || 'No declarado'
|
||||
}
|
||||
})
|
||||
.catch((res) => console.log(res));
|
||||
}
|
||||
|
||||
if (row[3]) {
|
||||
var marca = await Marca.findOrCreate({
|
||||
where: {
|
||||
marca: row[3] || 'No declarado'
|
||||
}
|
||||
})
|
||||
.catch((e) => { throw new Error(e); });
|
||||
}
|
||||
|
||||
if (row[12]) {
|
||||
var os = await OS.findOrCreate({
|
||||
where: {
|
||||
osname: row[12] || 'No declarado'
|
||||
}
|
||||
})
|
||||
.catch((e) => { throw new Error(e); });
|
||||
}
|
||||
|
||||
if (row[14]) {
|
||||
var uResponsable = await UResponsable.findOrCreate({
|
||||
where: {
|
||||
uResponsable: row[14] || 'No declarado'
|
||||
}
|
||||
})
|
||||
.catch((e) => { throw new Error(e); });
|
||||
}
|
||||
|
||||
if (row[16]) {
|
||||
var ubicacion = await Ubicacion.findOrCreate({
|
||||
where: {
|
||||
ubicacion: row[16] || 'No declarado'
|
||||
}
|
||||
})
|
||||
.catch((e) => { throw new Error(e); });
|
||||
}
|
||||
|
||||
if (row[17]) {
|
||||
var uso = await Uso.findOrCreate({
|
||||
where: {
|
||||
uso: row[17] || 'No declarado'
|
||||
}
|
||||
})
|
||||
.catch((e) => { throw new Error(e); });
|
||||
}
|
||||
|
||||
let equipo = {
|
||||
noInventario: row[0],
|
||||
activoFijo: activos.indexOf(row[1]) + 1,
|
||||
idActivoFijo: activoFijo[0]['idActivoFijo'],
|
||||
modelo: row[2],
|
||||
marca: marcas.indexOf(row[3]) + 1,
|
||||
marca: marca[0]['idMarca'],
|
||||
noSerie: row[4],
|
||||
procesador: row[5],
|
||||
vProcesador: row[6],
|
||||
@@ -119,22 +88,23 @@ const post = async(req, res) => {
|
||||
memoria: row[9],
|
||||
vMemoria: row[10],
|
||||
graficos: row[11],
|
||||
osname: os.indexOf(row[12]) + 1,
|
||||
osname: os[0]['idOS'],
|
||||
noResguardo: row[13],
|
||||
uResponsable: unidades.indexOf(row[14]) + 1,
|
||||
ubicacion: ubicaciones.indexOf(row[16]) + 1,
|
||||
uso: usos.indexOf(row[17]) + 1,
|
||||
uResponsable: uResponsable[0]['idUnidadResponsable'],
|
||||
ubicacion: ubicacion[0]['idUbicacion'],
|
||||
uso: uso[0]['idUso']
|
||||
}
|
||||
equipos.push(equipo);
|
||||
});
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
|
||||
var count = 0;
|
||||
for (equipo of equipos) {
|
||||
count++;
|
||||
await Inventario.create({
|
||||
noInventario: equipo.noInventario,
|
||||
noResguardo: equipo.noResguardo,
|
||||
idActivoFijo: equipo.activoFijo,
|
||||
idActivoFijo: equipo.idActivoFijo,
|
||||
idUnidadResponsable: equipo.uResponsable,
|
||||
idUbicacion: equipo.ubicacion,
|
||||
idUso: equipo.uso
|
||||
@@ -161,22 +131,27 @@ const post = async(req, res) => {
|
||||
noInventario: equipo.noInventario
|
||||
}
|
||||
});
|
||||
return res.status(500).json({
|
||||
res.status(500).json({
|
||||
ok: false,
|
||||
err
|
||||
})
|
||||
});
|
||||
throw new Error(e);
|
||||
})
|
||||
})
|
||||
.catch((e) => res.status(500).json({
|
||||
ok: false,
|
||||
e
|
||||
}))
|
||||
|
||||
.catch((e) => {
|
||||
res.status(500).json({
|
||||
ok: false,
|
||||
e
|
||||
});
|
||||
throw new Error(e);
|
||||
})
|
||||
}
|
||||
|
||||
res.json({
|
||||
ok: true,
|
||||
message: `${ count } records created successfully.`
|
||||
// equipos
|
||||
// activoF
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user