update: now admin can see other admins
This commit is contained in:
@@ -86,10 +86,13 @@ router.get("/user_profile/:userId", async (req, res) => {
|
|||||||
router.get("/users/:province", async (req, res) => {
|
router.get("/users/:province", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const province = req.params.province;
|
const province = req.params.province;
|
||||||
|
const requestingUser = await User.findById(req.userId);
|
||||||
|
|
||||||
const users = (await User.find({ province: province })).filter(
|
let users = await User.find({ province });
|
||||||
(item) => !item.permissions.includes("admin")
|
|
||||||
);
|
if (!requestingUser?.permissions?.includes("admin")) {
|
||||||
|
users = users.filter((item) => !item.permissions?.includes("admin"));
|
||||||
|
}
|
||||||
|
|
||||||
res.status(200).json(users);
|
res.status(200).json(users);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -125,7 +128,7 @@ router.put("/user/:userId", async (req, res) => {
|
|||||||
const updatedUser = await User.findByIdAndUpdate(
|
const updatedUser = await User.findByIdAndUpdate(
|
||||||
userId,
|
userId,
|
||||||
{ mobile, password, fullname, pic, province, permissions },
|
{ mobile, password, fullname, pic, province, permissions },
|
||||||
{ new: true } // Set { new: true } to return the updated document
|
{ new: true }, // Set { new: true } to return the updated document
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!updatedUser) {
|
if (!updatedUser) {
|
||||||
|
|||||||
Reference in New Issue
Block a user