Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions backend/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions backend/routers/users.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down