37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
const { validarAlfanumerico } = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Carrito = require(`${dbPath}/Carrito`);
|
|
const Equipo = require(`${dbPath}/Equipo`);
|
|
const Modulo = require(`${dbPath}/Modulo`);
|
|
const Programa = require(`${dbPath}/Programa`);
|
|
const Status = require(`${dbPath}/Status`);
|
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
|
|
|
const equipo = async (body) => {
|
|
const numeroInventario = validarAlfanumerico(
|
|
body.numeroInventario,
|
|
'El numero de inventario',
|
|
20
|
|
);
|
|
|
|
return Equipo.findOne({
|
|
where: { numeroInventario },
|
|
include: [
|
|
{ model: Carrito, include: [{ model: TipoCarrito }, { model: Modulo }] },
|
|
{ model: Status },
|
|
{ model: Programa },
|
|
],
|
|
}).then((res) => {
|
|
if (!res) throw new Error('No existe este equipo.');
|
|
delete res.dataValues.idCarrito;
|
|
delete res.dataValues.idPrograma;
|
|
delete res.dataValues.idStatus;
|
|
delete res.dataValues.Carrito.dataValues.idTipoCarrito;
|
|
delete res.dataValues.Carrito.dataValues.idModulo;
|
|
if (!res.Programa) delete res.dataValues.Programa;
|
|
return res;
|
|
});
|
|
};
|
|
|
|
module.exports = equipo;
|