From afde3f1475e8079a02f01eec20c4cdbe7732d2ea Mon Sep 17 00:00:00 2001 From: UO264802 <71766858+UO264802@users.noreply.github.com> Date: Sat, 30 Apr 2022 14:14:29 +0200 Subject: [PATCH] Eliminando orderController --- .github/workflows/asw2122.yml | 2 +- restapi/controllers/OrderController.ts | 62 -------------------------- restapi/routes/apiOrders.ts | 24 ---------- restapi/server.ts | 4 +- 4 files changed, 3 insertions(+), 89 deletions(-) delete mode 100644 restapi/controllers/OrderController.ts delete mode 100644 restapi/routes/apiOrders.ts diff --git a/.github/workflows/asw2122.yml b/.github/workflows/asw2122.yml index 12b5c13..7922e1a 100644 --- a/.github/workflows/asw2122.yml +++ b/.github/workflows/asw2122.yml @@ -85,7 +85,7 @@ jobs: user: ${{ secrets.DEPLOY_USER }} key: ${{ secrets.DEPLOY_KEY }} command: | - wget https://github.com/Arquisoft/dede_es6b/blob/develop/docker-compose-deploy.yml -O docker-compose.yml + wget https://github.com/Arquisoft/dede_es6b/blob/deploy/docker-compose-deploy.yml -O docker-compose.yml docker-compose stop docker-compose rm -f docker-compose pull diff --git a/restapi/controllers/OrderController.ts b/restapi/controllers/OrderController.ts deleted file mode 100644 index 28cc9bc..0000000 --- a/restapi/controllers/OrderController.ts +++ /dev/null @@ -1,62 +0,0 @@ -require("../utils/connectDB") - -import { Request, Response } from 'express'; -import Pedido from '../models/Order'; - -import Order from '../models/Order'; - -export const findOrdersByUserId = async (req: Request, res: Response): Promise => { - const pedidos = await Pedido.find({ id_usuario: req.params.id }); - return res.json(pedidos); -}; - - - - -var randomstring = require("randomstring"); - - -export const findAllOrders = async (req: Request, res: Response): Promise => { - const orders = await Order.find({}); - if(orders.length==0){ - return res.send("No hay pedidos") - } - return res.json(orders); -}; - - - - -export const findOrdersByUser = async (req: Request, res: Response): Promise => { - const orders = await Order.find({user_id:req.params.user_id}); - if(orders.length==0){ - return res.send("El usuario no tiene pedidos") - } - return res.json(orders); -}; - - -export const addOrder = async (req: Request, res: Response) => { - try{ - let order = new Order(); - order.code_order = randomstring.generate(); - order.user_id = req.body.user_id; - order.products = req.body.cartProducts; - //Actualizar el stock - order.price = req.body.price; - order.url = req.body.url; - order.date = Date.now(); - order.status = "PREPARÁNDOSE"; - - await order.save(); - res.send("Añadido pedido correctamente"); - }catch{ - res.send("Error al añadir pedido"); - } - - } - -function p(p: any, arg1: (Product: any) => void) { - throw new Error('Function not implemented.'); -} - diff --git a/restapi/routes/apiOrders.ts b/restapi/routes/apiOrders.ts deleted file mode 100644 index 597535a..0000000 --- a/restapi/routes/apiOrders.ts +++ /dev/null @@ -1,24 +0,0 @@ -import express, { Request, Response, Router } from 'express'; -import { addOrder, findAllOrders, findOrdersByUser } from '../controllers/OrderController'; - -const orderRouter = express.Router() - -let bd = require('../utils/connectDB') - -orderRouter.get("orders/list", findAllOrders); - -orderRouter.get("/list/:id", findOrdersByUser); - -orderRouter.get("/list", findAllOrders); - - - -orderRouter.get("/:user_id",findOrdersByUser); - -orderRouter.post("/add",addOrder); - - - - - -export default orderRouter; diff --git a/restapi/server.ts b/restapi/server.ts index 9927e3b..7954035 100644 --- a/restapi/server.ts +++ b/restapi/server.ts @@ -4,7 +4,7 @@ import bp from 'body-parser'; import promBundle from 'express-prom-bundle'; import apiProducts from "./routes/apiProducts"; -import apiOrders from "./routes/apiOrders"; +//import apiOrders from "./routes/apiOrders"; import apiPays from "./routes/apiPays"; import api from "./api" const app: Application = express(); @@ -25,7 +25,7 @@ app.use(express.json()); app.use("/api", api) app.use("/products",apiProducts) -app.use("/orders",apiOrders) +//app.use("/orders",apiOrders) app.use("/payments",apiPays) app.listen(port, ():void => {