equipos de un carrito listo
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user