diff --git a/restapi/routes/juguete.router.ts b/restapi/routes/juguete.router.ts index b5cde86..bdd9ae4 100644 --- a/restapi/routes/juguete.router.ts +++ b/restapi/routes/juguete.router.ts @@ -1,7 +1,5 @@ -import { Console } from "console"; import express, { Request, response, Response } from "express" import cloudinary from 'cloudinary'; -import { ObjectId } from "mongodb"; export const jugueteRouter = express.Router() const Juguete = require("../models/Juguete"); @@ -37,9 +35,7 @@ jugueteRouter.get("/withStock", async (req: Request, res: Response) => { jugueteRouter.get("/:nombre", async (req: Request, res: Response) => { try { let filter = { nombre: req.params.nombre } - //console.log(filter); let juguete = await Juguete.findOne(filter); - //console.log(juguete); if (juguete) { res.json(juguete); } @@ -83,7 +79,6 @@ async function borrarImagen(imagen: String) { */ jugueteRouter.post("/", async (req: Request, res: Response) => { try { - console.log("NUEVO JUGUETE"); let nuevoJuguete = { nombre: req.body.nombre, descripcion: req.body.descripcion, @@ -136,11 +131,8 @@ jugueteRouter.post("/addStock/:nombre", async (req: Request, res: Response) => { try { const filter = { nombre: req.params.nombre } var juguete = await Juguete.findOne(filter); - //console.log(juguete.stock) - //console.log(req.body.stock) const number: Number = juguete.stock + req.body.stock const stock = { stock: number } - //console.log(stock) var jugueteActualizado = await Juguete.findOneAndUpdate(filter, stock, { new: true }) res.send("Stock del juguete añadido correctamente"); @@ -148,26 +140,5 @@ 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 = { - 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/restapi/tests/juguete.test.ts b/restapi/tests/juguete.test.ts index d9a5e52..93b40a3 100644 --- a/restapi/tests/juguete.test.ts +++ b/restapi/tests/juguete.test.ts @@ -26,6 +26,7 @@ beforeAll(async () => { cloudinary.configTest(); gestorBd.connectTest(); + await prepararBd(); server = app.listen(port, ():void => { @@ -75,20 +76,6 @@ describe('juguete ', () => { const response:Response = await request(app).post('/juguete').send({nombre:name,descripcion:description,precio:price,imagen:imag,categoria:category,stock:stock}) expect(response.statusCode).toBe(200); expect(response.text).toEqual("Añadido nuevo juguete"); - - const next:Response = await request(app).get('/juguete/'+name); - expect(next.statusCode).toBe(200); - expect(next.body).toEqual({ - id : next.body.id, - nombre: name, - descripcion: description, - precio: price, - imagen: next.body.imagen, - categoria: category, - cantidad: 0, - stock:stock - }) - }); it("No se puede añadir un juguete que ya existe", async () => { diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index 4a989a5..73049f4 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -1,4 +1,4 @@ -import { QueryClient, QueryClientProvider, useQuery } from 'react-query' +import {useQuery } from 'react-query' import { useEffect, useState } from "react" @@ -12,7 +12,6 @@ import Navbar from './componentes/Navbar/Navbar'; import { Juguete } from './shared/sharedJuguete'; import Footer from './componentes/Footer/Footer'; import Drawer from '@material-ui/core/Drawer'; -import LinearProgess from '@material-ui/core/LinearProgress'; import Grid from '@material-ui/core/Grid'; import AddShoppingCartIcon from '@material-ui/icons/AddShoppingCart'; import Badge from '@material-ui/core/Badge'; @@ -65,7 +64,6 @@ export async function getJuguetes(): Promise { en la BD y exportando para poder usarlo desde fuera*/ //-------------------------------------------------------------------------------------------------------- -const queryClient = new QueryClient() const App = () => { const [cartOpen, setCartOpen] = useState(false); diff --git a/webapp/src/Cart/Cart.tsx b/webapp/src/Cart/Cart.tsx index 4170d40..3950a08 100644 --- a/webapp/src/Cart/Cart.tsx +++ b/webapp/src/Cart/Cart.tsx @@ -4,9 +4,6 @@ import { useAuth0 } from '@auth0/auth0-react'; import {Wrapper} from './Cart.styles'; import { Typography } from "@material-ui/core"; -//Types -import { CartItemType } from '../App'; - import {Juguete} from '../shared/sharedJuguete'; import LoginButtonCart from '../componentes/Login/LoginButtonCart'; diff --git a/webapp/src/CartItem/CartItem.tsx b/webapp/src/CartItem/CartItem.tsx index 8f55166..f130839 100644 --- a/webapp/src/CartItem/CartItem.tsx +++ b/webapp/src/CartItem/CartItem.tsx @@ -1,18 +1,12 @@ import Button from '@material-ui/core/Button'; + //types -import {CartItemType} from '../App'; -import Item from '../Item/Item'; import {Juguete} from '../shared/sharedJuguete'; //Styles import {Wrapper} from './CartItem.styles'; -/*type Props = { - item: CartItemType; - addToCart: (clickedItem: CartItemType) => void; - removeFromCart: (id:number) => void; -}*/ type Props = { item: Juguete; diff --git a/webapp/src/Item/Item.tsx b/webapp/src/Item/Item.tsx index cdc0a08..a284dc5 100644 --- a/webapp/src/Item/Item.tsx +++ b/webapp/src/Item/Item.tsx @@ -1,20 +1,12 @@ import Button from '@material-ui/core/Button'; //Types -//import { CartItemType } from '../App'; //Styles import { Wrapper } from './Item.styles'; import { Juguete } from '../shared/sharedJuguete'; -import { BrowserRouter, useNavigate } from "react-router-dom"; -import getRoleUsuario from "../componentes/Login/LoginButton" -import { Router } from 'express'; -/*type Props = { - item: CartItemType; - handleAddToCart: (clickedItem: CartItemType) => void; -}*/ type Props = { item: Juguete; handleAddToCart: (clickedItem: Juguete) => void; diff --git a/webapp/src/PayForm/Delivery.tsx b/webapp/src/PayForm/Delivery.tsx index 7563095..4009992 100644 --- a/webapp/src/PayForm/Delivery.tsx +++ b/webapp/src/PayForm/Delivery.tsx @@ -1,16 +1,12 @@ import * as React from "react"; -import CartItem from '../CartItem/CartItem'; -import { useAuth0 } from '@auth0/auth0-react'; import Button from "@mui/material/Button"; import { Typography } from "@material-ui/core"; import Card from '@mui/material/Card'; import CardActions from '@mui/material/CardActions'; import CardContent from '@mui/material/CardContent'; -import CardMedia from '@mui/material/CardMedia'; import Paper from "@mui/material/Paper"; -//Types -import { CartItemType } from '../App'; +//Types import {Juguete} from '../shared/sharedJuguete'; type Props = { diff --git a/webapp/src/PayForm/FinalizedOrder.tsx b/webapp/src/PayForm/FinalizedOrder.tsx index 1405b11..fc6ae8d 100644 --- a/webapp/src/PayForm/FinalizedOrder.tsx +++ b/webapp/src/PayForm/FinalizedOrder.tsx @@ -1,9 +1,4 @@ -import * as React from "react"; -import CartItem from '../CartItem/CartItem'; -import { useAuth0 } from '@auth0/auth0-react'; //Types -import { CartItemType } from '../App'; -import {Juguete} from '../shared/sharedJuguete'; import { Typography } from "@material-ui/core"; export default function FinalizedOrder(props: any): JSX.Element { diff --git a/webapp/src/PayForm/ProcesoPago.tsx b/webapp/src/PayForm/ProcesoPago.tsx index f8715dc..d280f16 100644 --- a/webapp/src/PayForm/ProcesoPago.tsx +++ b/webapp/src/PayForm/ProcesoPago.tsx @@ -91,11 +91,11 @@ const ProcesoPago: React.FC = ({ cartItems }) => { }; const siguientePasoSiPodCalcularEnvio = async () => { - if (localStorage.getItem("direccion") == null || localStorage.getItem("direccion") == "") { + if (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(); - if (gastosEnvio == 0.00 || localStorage.getItem("direccion") == "null") { + if (gastosEnvio === 0.00 || localStorage.getItem("direccion") === "null") { toast.error("Su dirección no fue encontrada, lo sentimos. Para solucionar el problema " + "modifique la dirección de su POD", { position: toast.POSITION.TOP_CENTER }) } else { @@ -112,7 +112,6 @@ const ProcesoPago: React.FC = ({ cartItems }) => { const getPaso = (stepIndex: number) => { switch (stepIndex) { case 0: - condPedido = true; return ( {