From 0f31fd1679f02a716dac635bff5f74cc39b85167 Mon Sep 17 00:00:00 2001 From: soleil00 Date: Fri, 15 Aug 2025 17:15:32 +0200 Subject: [PATCH] feat: add getAlladmins endpoint to admin controller later on it will protected --- src/controllers/admin/index.ts | 11 ++++++++++- src/routes/admin.routes.ts | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/controllers/admin/index.ts b/src/controllers/admin/index.ts index 5a061547..2441c623 100644 --- a/src/controllers/admin/index.ts +++ b/src/controllers/admin/index.ts @@ -86,4 +86,13 @@ export const getAdminInfo = async (req: Request, res: Response) => { } catch (error) { return res.status(401).json({ message: "Invalid or expired token.", error }); } -}; \ No newline at end of file +}; + +export const getAlladmins = async (req: Request, res: Response) => { + try { + const admins = await Admin.find(); + return res.status(200).json(admins); + } catch (error) { + return res.status(500).json({ message: "An error occurred while fetching admins.", error }); + } +} \ No newline at end of file diff --git a/src/routes/admin.routes.ts b/src/routes/admin.routes.ts index 7df23f3f..53256e25 100644 --- a/src/routes/admin.routes.ts +++ b/src/routes/admin.routes.ts @@ -1,5 +1,5 @@ import { Router } from "express"; -import { activateAdmin, deactivateAdmin, getAdminInfo, loginAdmin, registerAdmin } from "../controllers/admin"; +import { activateAdmin, deactivateAdmin, getAdminInfo, getAlladmins, loginAdmin, registerAdmin } from "../controllers/admin"; @@ -7,6 +7,7 @@ import { activateAdmin, deactivateAdmin, getAdminInfo, loginAdmin, registerAdmin const adminRoutes = Router(); adminRoutes.get("/me", getAdminInfo); +adminRoutes.get("/", getAlladmins); adminRoutes.post("/register", registerAdmin); adminRoutes.post("/login", loginAdmin); adminRoutes.put("/deactivate/:id", deactivateAdmin);