Skip to content

Commit

Permalink
Mas limpieza de codigo
Browse files Browse the repository at this point in the history
  • Loading branch information
UO271728 committed May 3, 2022
1 parent 53f9fd4 commit 567cb05
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 36 deletions.
1 change: 0 additions & 1 deletion restapi/routes/juguete.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ jugueteRouter.post("/", async (req: Request, res: Response) => {
categoria: req.body.categoria,
stock: req.body.stock
};
console.log(nuevoJuguete);
let juguete = await Juguete.findOne({ nombre: nuevoJuguete.nombre });
if (juguete) {
res.send("Este juguete ya existe");
Expand Down
25 changes: 0 additions & 25 deletions restapi/routes/pedido.router.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { match } from "assert";
import { Console } from "console";
import express, {Request,response,Response} from "express"
import { maxHeaderSize, request } from "http";
import { ObjectId } from "mongodb";

const Juguete = require("../models/Juguete");
const Pedido = require('../models/Pedido')
Expand All @@ -21,7 +17,6 @@ const geocoder = ApiGeocode(opciones);
pedidoRouter.get("/", async(req:Request,res:Response)=>{
try{
let pedidos = await Pedido.find({}).populate('juguetes._id').populate('usuario');
console.log(pedidos)
res.send(pedidos);
} catch {
res.status(500).send("Error al listar los pedidos");
Expand Down Expand Up @@ -130,22 +125,6 @@ pedidoRouter.post('/gastosEnvio', async (req:Request,res:Response) =>{
}
});


/*
pedidoRouter.get("/:_id", async(req:Request,res:Response)=>{
try{
var pedido = await PedidoRepository.findPedido({"_id":req.params._id});
if(pedido){
res.send(pedido);
} else{
res.send("El pedido no existe");
}
} catch (error){
res.send("Error al encontrar el pedido");
}
});
*/

pedidoRouter.get("/byUser/:user", async(req:Request,res:Response)=>{
try{
var usuario = await Usuario.findOne({"email":req.params.user,"isAdmin":false});
Expand Down Expand Up @@ -199,7 +178,6 @@ async function procesarJuguetes(juguetes:any): Promise<any> {

pedidoRouter.post("/", async (req:Request,res:Response) =>{
try{
console.log(req.body.usuario);
let productos = await procesarJuguetes(req.body.productos);
if(productos.length == 0){
res.send("No se pudo crear el pedido por falta de stock");
Expand All @@ -217,15 +195,12 @@ pedidoRouter.post("/", async (req:Request,res:Response) =>{
juguetes: productos,
usuario:user._id
}
console.log(nuevoPedido);
let pedido = new Pedido(nuevoPedido);
console.log(pedido);
var error = pedido.validateSync();
if(error){
res.status(500).send(error);
} else{
await pedido.save();
console.log("creado");
res.send("Su pedido ha sido tramitado");
}

Expand Down
2 changes: 0 additions & 2 deletions restapi/routes/usuario.router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Console } from "console";
import express, {Request,response,Response} from "express"
import { ObjectId } from "mongodb";

export const usuarioRouter = express.Router()
const Usuario = require('../models/Usuario')
Expand Down
1 change: 0 additions & 1 deletion restapi/tests/juguete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ describe('juguete ', () => {

it("Se puede eliminar un juguete", async () =>{
const response: Response = await request(app).delete('/juguete/juguete1Prueba');
console.log("eliminar");
expect(response.status).toBe(200);
expect(response.text).toEqual("Eliminado juguete")
});
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/PayForm/ProcesoPago.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Props = {
type Props = {
cartItems: Juguete[];
};
let condPedido = true;
let gastosEnvio: any;

//Procesar pedido
Expand Down Expand Up @@ -98,6 +97,7 @@ const ProcesoPago: React.FC<Props> = ({ cartItems }) => {
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 })
variable++;
} else {
setPasoActual((pasoPrevio) => pasoPrevio + 1);
}
Expand Down
9 changes: 3 additions & 6 deletions webapp/src/componentes/editarProducto/editarProducto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@ var precio: number;

async function getJuguete(): Promise<Juguete> {
//const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/'
const apiEndPoint = process.env.API_URL || 'http://localhost:5000/'
const apiEndPoint = process.env.API_URL || 'http://localhost:5000'
let partes = url.split('/');
let response = await fetch(apiEndPoint + "/juguete/" + partes[partes.length - 1]);
//The objects returned by the api are directly convertible to User objects
let j = response.json();
console.log(j);
return j;
}

async function updateJuguete(): Promise<any> {
const apiEndPoint = process.env.API_URL || 'http://localhost:5000/'
//console.log(process.env.REACT_APP_API_URI)
//const apiEndPoint = process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/'
const apiEndPoint = process.env.API_URL || 'http://localhost:5000'
let partes = url.split('/');
let response = await fetch(apiEndPoint + "juguete/update/" + partes[partes.length - 1], {
let response = await fetch(apiEndPoint + "/juguete/update/" + partes[partes.length - 1], {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
Expand Down

0 comments on commit 567cb05

Please sign in to comment.