From 65bd1fed57f8b449f4dbe1aabbbc075d9bd03acc Mon Sep 17 00:00:00 2001 From: uo277819 Date: Sat, 30 Apr 2022 17:28:39 +0200 Subject: [PATCH 01/15] Prototipo finalizar pedido --- restapi/routes/juguete.router.ts | 21 ++++++++++++++++++ webapp/src/PayForm/ProcesoPago.tsx | 34 ++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/restapi/routes/juguete.router.ts b/restapi/routes/juguete.router.ts index facb18c..f934405 100644 --- a/restapi/routes/juguete.router.ts +++ b/restapi/routes/juguete.router.ts @@ -142,4 +142,25 @@ jugueteRouter.post("/addStock/:nombre", async (req:Request,res:Response) => { } }); +jugueteRouter.post("/subtock/:nombre", async (req:Request,res:Response) => { + try{ + const filter = { + nombre: req.params.nombre, + } + + var juguete = await JugueteRepository.findJuguete(filter); + + const stock = {stock: juguete.stock - req.body.stock} + + var jugueteActualizado = await JugueteRepository.updateJuguete(filter,stock); + if(jugueteActualizado){ + res.send("Stock del juguete restado correctamente"); + } else{ + res.status(500).send("No se pudo restar stock al producto") + } + }catch (error){ + res.status(500).send("Error al restar stock al juguete") + } +}); + export default jugueteRouter; diff --git a/webapp/src/PayForm/ProcesoPago.tsx b/webapp/src/PayForm/ProcesoPago.tsx index 8ba8b89..a401899 100644 --- a/webapp/src/PayForm/ProcesoPago.tsx +++ b/webapp/src/PayForm/ProcesoPago.tsx @@ -37,6 +37,16 @@ type Props = { let gastosEnvio:any; +//restarsTock +async function subStock(nombre: string, cantidad: string): Promise { + const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + let response = await fetch(apiEndPoint + 'juguete/subStock/' + nombre, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ "stock": cantidad }) + }); +} + // Petición para obtener los gastos de envio async function getGastosEnvio(): Promise { const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' @@ -116,15 +126,21 @@ const ProcesoPago:React.FC = ({cartItems}) => { /> ); case 3: - return ; - + cartItems.map((elem)=>{ + subStock(elem.nombre,""+elem.cantidad); + }) + return( + + ); + } }; From 8e56e21135ac70e85806be4b0768cfdab06f818c Mon Sep 17 00:00:00 2001 From: Jorge Date: Sat, 30 Apr 2022 18:34:18 +0200 Subject: [PATCH 02/15] Nav --- webapp/src/componentes/Navbar/Menitems.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/webapp/src/componentes/Navbar/Menitems.tsx b/webapp/src/componentes/Navbar/Menitems.tsx index 3c08027..7f35186 100644 --- a/webapp/src/componentes/Navbar/Menitems.tsx +++ b/webapp/src/componentes/Navbar/Menitems.tsx @@ -8,5 +8,10 @@ export const MenuItems =[ title: 'Productos', url:'productos', cName:'nav-links' + }, + { + title: 'Historial Pedidos', + url:'pedidos', + cName:'nav-links' } ] \ No newline at end of file From a9c4a95da64271ff35637956e1e9747e35e9acbb Mon Sep 17 00:00:00 2001 From: Jorge Date: Sat, 30 Apr 2022 19:44:02 +0200 Subject: [PATCH 03/15] Intento listar pedidos --- restapi/routes/juguete.router.ts | 4 +-- webapp/src/App.tsx | 17 ++++++++- webapp/src/componentes/Login/LoginButton.tsx | 24 ++++++------- webapp/src/componentes/Pedidos/historial.tsx | 37 ++++++++++++++++++++ webapp/src/shared/sharedPedido.ts | 10 ++++++ 5 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 webapp/src/componentes/Pedidos/historial.tsx create mode 100644 webapp/src/shared/sharedPedido.ts diff --git a/restapi/routes/juguete.router.ts b/restapi/routes/juguete.router.ts index 40102da..c6273b7 100644 --- a/restapi/routes/juguete.router.ts +++ b/restapi/routes/juguete.router.ts @@ -158,7 +158,7 @@ jugueteRouter.post("/addStock/:nombre", async (req:Request,res:Response) => { res.status(500).send("Error al añadir stock al juguete") } }); - +/* jugueteRouter.post("/subtock/:nombre", async (req:Request,res:Response) => { try{ const filter = { @@ -179,5 +179,5 @@ jugueteRouter.post("/subtock/:nombre", async (req:Request,res:Response) => { res.status(500).send("Error al restar stock al juguete") } }); - +*/ export default jugueteRouter; diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index fc4eb1d..a3312d6 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -18,6 +18,7 @@ import AddShoppingCartIcon from '@material-ui/icons/AddShoppingCart'; import Badge from '@material-ui/core/Badge'; import Home from './paginas/Home'; import ContactUs from './paginas/ContactUs'; +import HistorialPedidos from './componentes/Pedidos/historial'; //Styles import { Wrapper, StyledButton } from './App.styles'; //import Profile from './componentes/loginSOLID/Profile'; @@ -340,6 +341,21 @@ const App = () => { } /> + + +

No tiene acceso a esa dirección

+