diff --git a/server/controller/Carrito/equiposCarrito.js b/server/controller/Carrito/equiposCarrito.js index 0e9f067..6d2ee2a 100644 --- a/server/controller/Carrito/equiposCarrito.js +++ b/server/controller/Carrito/equiposCarrito.js @@ -1,9 +1,29 @@ const validar = require('../../helper/validar'); const dbPath = '../../db/tablas'; const Carrito = require(`${dbPath}/Carrito`); -const Modulo = require(`${dbPath}/Modulo`); -const TipoCarrito = require(`${dbPath}/TipoCarrito`); +const Equipo = require(`${dbPath}/Equipo`); +const Programa = require(`${dbPath}/Programa`); +const Status = require(`${dbPath}/Status`); -const equiposCarrito = async (body) => {}; +const equiposCarrito = async (body) => { + const idCarrito = validar.validarId(body.idCarrito); + + return Carrito.findOne({ where: { idCarrito } }) + .then((res) => { + if (!res) throw new Error('No existe este carrito.'); + return Equipo.findAndCountAll({ + where: { idCarrito }, + include: [{ model: Status }, { model: Programa }], + }); + }) + .then((res) => { + for (let i = 0; i < res.rows.length; i++) { + delete res.rows[i].dataValues.idCarrito; + delete res.rows[i].dataValues.idStatus; + delete res.rows[i].dataValues.idPrograma; + } + return { count: res.count, equiposCarrito: res.rows }; + }); +}; module.exports = equiposCarrito; diff --git a/server/routes/Carrito.js b/server/routes/Carrito.js new file mode 100644 index 0000000..ae32523 --- /dev/null +++ b/server/routes/Carrito.js @@ -0,0 +1,31 @@ +const express = require('express'); +const app = express(); +const { verificaToken } = require('../middleware/autentificacion'); +const route = '/carrito'; +const controllerPath = '../controller/Carrito'; +const equiposCarrito = require(`${controllerPath}/equiposCarrito`); +// const update = require(`${controllerPath}/update`); + +// PUT +// app.put(`${route}/update`, (req, res) => { +// return update(req.body) +// .then((data) => { +// res.status(200).json(data); +// }) +// .catch((err) => { +// res.status(400).json({ message: err.message }); +// }); +// }); + +//GET +app.get(`${route}/equipos_carrito`, (req, res) => { + return equiposCarrito(req.query) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + +module.exports = app; diff --git a/server/routes/index.js b/server/routes/index.js index 349bae6..d2292d1 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,6 +1,7 @@ const express = require('express'); const app = express(); +app.use(require('./Carrito')); app.use(require('./Equipo')); app.use(require('./Modulo')); app.use(require('./Operador'));