Files
pcpuma_acatlan_api/server/controller/Carrito/equiposCarrito.js
T

30 lines
898 B
JavaScript
Raw Normal View History

2021-05-26 19:47:13 -05:00
const { validarId } = require('../../helper/validar');
2021-05-26 19:14:11 -05:00
const dbPath = '../../db/tablas';
const Carrito = require(`${dbPath}/Carrito`);
2021-05-26 19:27:35 -05:00
const Equipo = require(`${dbPath}/Equipo`);
const Programa = require(`${dbPath}/Programa`);
const Status = require(`${dbPath}/Status`);
2021-05-26 19:14:11 -05:00
2021-05-26 19:27:35 -05:00
const equiposCarrito = async (body) => {
2021-05-26 19:47:13 -05:00
const idCarrito = validarId(body.idCarrito);
2021-05-26 19:27:35 -05:00
return Carrito.findOne({ where: { idCarrito } })
.then((res) => {
if (!res) throw new Error('No existe este carrito.');
2021-05-26 19:47:13 -05:00
return Equipo.findAll({
2021-05-26 19:27:35 -05:00
where: { idCarrito },
include: [{ model: Status }, { model: Programa }],
});
})
.then((res) => {
2021-05-26 19:47:13 -05:00
for (let i = 0; i < res.length; i++) {
delete res[i].dataValues.idCarrito;
delete res[i].dataValues.idStatus;
delete res[i].dataValues.idPrograma;
2021-05-26 19:27:35 -05:00
}
2021-05-26 19:47:13 -05:00
return res;
2021-05-26 19:27:35 -05:00
});
};
2021-05-26 19:14:11 -05:00
module.exports = equiposCarrito;