From 39d6157a3c9e05d5558d88aa16fc3e28d1b9bf9d Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 7 Apr 2022 07:36:43 +0200 Subject: [PATCH 1/4] Fix naming issues in routers and remove unnecessary files --- src/controller/orders.controller.ts | 2 +- src/controller/organisations.controller.ts | 6 +++--- src/controller/testcontroller.controller.ts | 5 ----- src/index.ts | 2 -- src/routes/testrouter.route.ts | 12 ------------ 5 files changed, 4 insertions(+), 23 deletions(-) delete mode 100644 src/controller/testcontroller.controller.ts delete mode 100644 src/routes/testrouter.route.ts diff --git a/src/controller/orders.controller.ts b/src/controller/orders.controller.ts index 164c380..0bfebe0 100644 --- a/src/controller/orders.controller.ts +++ b/src/controller/orders.controller.ts @@ -79,7 +79,7 @@ export const getOrder = async (req: Request, res: Response) => { }); } - const order = await prisma.restaurant.findUnique({ + const order = await prisma.order.findUnique({ where: { id: id, }, diff --git a/src/controller/organisations.controller.ts b/src/controller/organisations.controller.ts index 4af0f52..d0b0030 100644 --- a/src/controller/organisations.controller.ts +++ b/src/controller/organisations.controller.ts @@ -7,7 +7,7 @@ export const addOrganization = async (req: Request, res: Response) => { if (typeof req.body.name !== "string" || typeof req.body.domain !== "string") { res.status(HttpStatusCodes.BAD_REQUEST).json({ name: DataType.STRING, - description: DataType.STRING, + domain: DataType.STRING, }); return; } @@ -32,7 +32,7 @@ export const updateOrganization = async (req: Request, res: Response) => { } else if (typeof req.body.name !== "string" || typeof req.body.domain !== "string") { res.status(HttpStatusCodes.BAD_REQUEST).json({ name: DataType.STRING, - description: DataType.STRING, + domain: DataType.STRING, }); return; } @@ -77,7 +77,7 @@ export const getOrganization = async (req: Request, res: Response) => { }); } - const organization = await prisma.restaurant.findUnique({ + const organization = await prisma.organization.findUnique({ where: { id: id, }, diff --git a/src/controller/testcontroller.controller.ts b/src/controller/testcontroller.controller.ts deleted file mode 100644 index cb7ef10..0000000 --- a/src/controller/testcontroller.controller.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Request, Response } from "express"; - -export const sayHello = async (request: Request, response: Response) => { - response.status(200).send("Hello!"); -}; diff --git a/src/index.ts b/src/index.ts index 6423178..3d5f077 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,12 @@ import express from "express"; const app = express(); -const testRoutes = require("./routes/testrouter.route"); const ordersRoutes = require("./routes/orders.route"); const organizationsRoutes = require("./routes/organisations.route"); const pizzasRoutes = require("./routes/pizzas.route"); const restaurantsRoutes = require("./routes/restaurants.route"); app.use(express.json()); -app.use("/tests", testRoutes); app.use("/order", ordersRoutes); app.use("/organization", organizationsRoutes); app.use("/pizza", pizzasRoutes); diff --git a/src/routes/testrouter.route.ts b/src/routes/testrouter.route.ts deleted file mode 100644 index 721a764..0000000 --- a/src/routes/testrouter.route.ts +++ /dev/null @@ -1,12 +0,0 @@ -import express from "express"; -import { sayHello } from "../controller/testcontroller.controller"; - -export const router = express.Router(); - -router.get("/", (request: Request, response: Response) => { - response.status(200).send("Cool test stuff!"); -}); - -router.post("/test1", sayHello); - -module.exports = router; From 1b162b4f3cf94e9842b155d620088e0201d78ebb Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Wed, 4 May 2022 11:08:50 +0200 Subject: [PATCH 2/4] Add "get all" endpoints --- src/controller/orders.controller.ts | 6 ++++++ src/controller/organisations.controller.ts | 6 ++++++ src/controller/pizzas.controller.ts | 6 ++++++ src/controller/restaurants.controller.ts | 6 ++++++ src/index.ts | 2 +- src/routes/orders.route.ts | 3 ++- src/routes/organisations.route.ts | 2 ++ src/routes/pizzas.route.ts | 3 ++- src/routes/restaurants.route.ts | 9 ++++++++- 9 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/controller/orders.controller.ts b/src/controller/orders.controller.ts index 0bfebe0..9fa3eba 100644 --- a/src/controller/orders.controller.ts +++ b/src/controller/orders.controller.ts @@ -87,3 +87,9 @@ export const getOrder = async (req: Request, res: Response) => { res.status(HttpStatusCodes.OK).json(order); }; + +export const getOrders = async (_req: Request, res: Response) => { + const orders = await prisma.order.findMany(); + + res.status(HttpStatusCodes.OK).json(orders); +}; diff --git a/src/controller/organisations.controller.ts b/src/controller/organisations.controller.ts index d0b0030..cc2184f 100644 --- a/src/controller/organisations.controller.ts +++ b/src/controller/organisations.controller.ts @@ -85,3 +85,9 @@ export const getOrganization = async (req: Request, res: Response) => { res.status(HttpStatusCodes.OK).json(organization); }; + +export const getOrganizations = async (_req: Request, res: Response) => { + const organizations = await prisma.organization.findMany(); + + res.status(HttpStatusCodes.OK).json(organizations); +}; diff --git a/src/controller/pizzas.controller.ts b/src/controller/pizzas.controller.ts index a96ea14..8b392f8 100644 --- a/src/controller/pizzas.controller.ts +++ b/src/controller/pizzas.controller.ts @@ -96,3 +96,9 @@ export const getPizza = async (req: Request, res: Response) => { res.status(HttpStatusCodes.OK).json(pizza); }; + +export const getPizzas = async (_req: Request, res: Response) => { + const pizzas = await prisma.pizza.findMany(); + + res.status(HttpStatusCodes.OK).json(pizzas); +}; diff --git a/src/controller/restaurants.controller.ts b/src/controller/restaurants.controller.ts index 68b2a03..abec94b 100644 --- a/src/controller/restaurants.controller.ts +++ b/src/controller/restaurants.controller.ts @@ -85,3 +85,9 @@ export const getRestaurant = async (req: Request, res: Response) => { res.status(HttpStatusCodes.OK).json(restaurant); }; + +export const getRestaurants = async (_req: Request, res: Response) => { + const restaurants = await prisma.restaurant.findMany(); + + res.status(HttpStatusCodes.OK).json(restaurants); +} diff --git a/src/index.ts b/src/index.ts index 3d5f077..76322d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ app.use("/pizza", pizzasRoutes); app.use("/restaurant", restaurantsRoutes); async function main() { - app.get("/", (req, res) => { + app.get("/", (_req, res) => { res.send("Hello World!"); }); diff --git a/src/routes/orders.route.ts b/src/routes/orders.route.ts index f10a514..c7b618f 100644 --- a/src/routes/orders.route.ts +++ b/src/routes/orders.route.ts @@ -1,8 +1,9 @@ import express from "express"; -import { addOrder, deleteOrder, getOrder, updateOrder } from "../controller/orders.controller"; +import { addOrder, deleteOrder, getOrder, updateOrder, getOrders } from "../controller/orders.controller"; const router = express.Router(); +router.get("/", getOrders); router.get("/:id", getOrder); router.post("/", addOrder); router.put("/:id", updateOrder); diff --git a/src/routes/organisations.route.ts b/src/routes/organisations.route.ts index de68ac0..9a44d25 100644 --- a/src/routes/organisations.route.ts +++ b/src/routes/organisations.route.ts @@ -1,5 +1,6 @@ import express from "express"; import { + getOrganizations, addOrganization, deleteOrganization, getOrganization, @@ -8,6 +9,7 @@ import { const router = express.Router(); +router.get("/organizations", getOrganizations); router.get("/:id", getOrganization); router.post("/", addOrganization); router.put("/:id", updateOrganization); diff --git a/src/routes/pizzas.route.ts b/src/routes/pizzas.route.ts index fed4038..4fec840 100644 --- a/src/routes/pizzas.route.ts +++ b/src/routes/pizzas.route.ts @@ -1,8 +1,9 @@ import express from "express"; -import { addPizza, deletePizza, getPizza, updatePizza } from "../controller/pizzas.controller"; +import { getPizzas, addPizza, deletePizza, getPizza, updatePizza } from "../controller/pizzas.controller"; const router = express.Router(); +router.get("/", getPizzas); router.get("/:id", getPizza); router.post("/", addPizza); router.put("/:id", updatePizza); diff --git a/src/routes/restaurants.route.ts b/src/routes/restaurants.route.ts index 077662b..a2f98fd 100644 --- a/src/routes/restaurants.route.ts +++ b/src/routes/restaurants.route.ts @@ -1,8 +1,15 @@ import express from "express"; -import { addRestaurant, deleteRestaurant, getRestaurant, updateRestaurant } from "../controller/restaurants.controller"; +import { + getRestaurants, + addRestaurant, + deleteRestaurant, + getRestaurant, + updateRestaurant, +} from "../controller/restaurants.controller"; const router = express.Router(); +router.get("/restaurants", getRestaurants); router.get("/:id", getRestaurant); router.post("/", addRestaurant); router.put("/:id", updateRestaurant); From 8c58e1f08919f71878d34d2b1e205f49ff21fac3 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Wed, 4 May 2022 11:12:15 +0200 Subject: [PATCH 3/4] Fix routes --- src/routes/organisations.route.ts | 2 +- src/routes/restaurants.route.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/organisations.route.ts b/src/routes/organisations.route.ts index 9a44d25..d7ff6e4 100644 --- a/src/routes/organisations.route.ts +++ b/src/routes/organisations.route.ts @@ -9,7 +9,7 @@ import { const router = express.Router(); -router.get("/organizations", getOrganizations); +router.get("/", getOrganizations); router.get("/:id", getOrganization); router.post("/", addOrganization); router.put("/:id", updateOrganization); diff --git a/src/routes/restaurants.route.ts b/src/routes/restaurants.route.ts index a2f98fd..6ab38e3 100644 --- a/src/routes/restaurants.route.ts +++ b/src/routes/restaurants.route.ts @@ -9,7 +9,7 @@ import { const router = express.Router(); -router.get("/restaurants", getRestaurants); +router.get("/", getRestaurants); router.get("/:id", getRestaurant); router.post("/", addRestaurant); router.put("/:id", updateRestaurant); From 6f9a7260b659f54ccfbf6f4a1e9d4cf3f2f2a538 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Wed, 4 May 2022 11:50:02 +0200 Subject: [PATCH 4/4] Fix formatting --- src/controller/restaurants.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/restaurants.controller.ts b/src/controller/restaurants.controller.ts index abec94b..4f3ea83 100644 --- a/src/controller/restaurants.controller.ts +++ b/src/controller/restaurants.controller.ts @@ -90,4 +90,4 @@ export const getRestaurants = async (_req: Request, res: Response) => { const restaurants = await prisma.restaurant.findMany(); res.status(HttpStatusCodes.OK).json(restaurants); -} +};