diff --git a/backend/controllers/user.controller.js b/backend/controllers/user.controller.js index e9764765..a6cbbdac 100644 --- a/backend/controllers/user.controller.js +++ b/backend/controllers/user.controller.js @@ -26,6 +26,23 @@ UserController.user_list = async function (req, res) { } }; +// Get list of Users with accessLevel 'admin' or 'superadmin' with GET +UserController.admin_list = async function (req, res) { + const { headers } = req; + + if (headers['x-customrequired-header'] !== expectedHeader) { + return res.sendStatus(403); + } + + try { + const admins = await User.find({ accessLevel: { $in: ["admin", "superadmin"] } }); + return res.status(200).send(admins); + } catch (err) { + return res.sendStatus(400); + } +}; + + // Get User by id with GET UserController.user_by_id = async function (req, res) { const { headers } = req; diff --git a/backend/routers/users.router.js b/backend/routers/users.router.js index db4efb23..a611cfac 100644 --- a/backend/routers/users.router.js +++ b/backend/routers/users.router.js @@ -6,6 +6,8 @@ const { UserController } = require('../controllers'); // The base is /api/users router.get('/', UserController.user_list); +router.get('/admins', UserController.admin_list); + router.post('/', UserController.create); router.get('/:UserId', UserController.user_by_id);