Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an API that fetches all the admins #1774

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
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
Loading