diff --git a/src/controller/orders.controller.ts b/src/controller/orders.controller.ts index 164c380..9fa3eba 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, }, @@ -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 6f850cd..cc2184f 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; } @@ -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..4f3ea83 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/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 0e282ac..1cbf928 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,13 +26,16 @@ app.use((err: any, req: Request, res: Response, next: NextFunction) => { } }); +app.use("/auth", adminRoutes); +app.use("/order", ordersRoutes); +app.use("/organization", organizationsRoutes); +app.use("/pizza", pizzasRoutes); +app.use("/restaurant", restaurantsRoutes); + async function main() { - app.use("/api/auth", adminRoutes); - app.use(express.json()); - app.use("/order", ordersRoutes); - app.use("/organization", organizationsRoutes); - app.use("/pizza", pizzasRoutes); - app.use("/restaurant", restaurantsRoutes); + app.get("/", (_req, res) => { + res.send("Hello World!"); + }); app.listen(3000, () => { console.log("Server is running on port 3000"); 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..d7ff6e4 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("/", 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..6ab38e3 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("/", getRestaurants); router.get("/:id", getRestaurant); router.post("/", addRestaurant); router.put("/:id", updateRestaurant); 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;