From 65bd1fed57f8b449f4dbe1aabbbc075d9bd03acc Mon Sep 17 00:00:00 2001 From: uo277819 Date: Sat, 30 Apr 2022 17:28:39 +0200 Subject: [PATCH 01/22] 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/22] 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 15b848e3d2e25e1c93c12b3b5119c5fb3a3cb02d Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 30 Apr 2022 18:57:41 +0200 Subject: [PATCH 03/22] Mas cosas de categorias y error null --- webapp/src/PayForm/CategoriesBar.tsx | 4 ++++ webapp/src/PayForm/ProcesoPago.tsx | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/webapp/src/PayForm/CategoriesBar.tsx b/webapp/src/PayForm/CategoriesBar.tsx index 7042259..42841ea 100644 --- a/webapp/src/PayForm/CategoriesBar.tsx +++ b/webapp/src/PayForm/CategoriesBar.tsx @@ -23,6 +23,10 @@ const CategoriesBar = ()=> { <> Nostalgia + Vehiculos + Aire libre + Algo + Otros Productos diff --git a/webapp/src/PayForm/ProcesoPago.tsx b/webapp/src/PayForm/ProcesoPago.tsx index 458e92c..4f09a52 100644 --- a/webapp/src/PayForm/ProcesoPago.tsx +++ b/webapp/src/PayForm/ProcesoPago.tsx @@ -60,7 +60,7 @@ const ProcesoPago:React.FC = ({cartItems}) => { }; const siguientePasoSiPodCalcularEnvio = async () => { - if(localStorage.getItem("direccion")==null || localStorage.getItem("direccion")=="") { + if(localStorage.getItem("direccion")==null || localStorage.getItem("direccion")=="null"|| localStorage.getItem("direccion")=="") { toast.warn("Por favor, inicie sesión con su POD para que podamos obtener su dirección", {position: toast.POSITION.TOP_CENTER}) } else { let variable = await getGastosEnvio(); From a9c4a95da64271ff35637956e1e9747e35e9acbb Mon Sep 17 00:00:00 2001 From: Jorge Date: Sat, 30 Apr 2022 19:44:02 +0200 Subject: [PATCH 04/22] 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

+