Skip to content

Commit

Permalink
Fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sridhar-5 committed Aug 24, 2021
1 parent 42940af commit 10b54cf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
9 changes: 7 additions & 2 deletions middleware/RedirectAdminUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ module.exports = async function (request, response, next) {
const CheckUsersIsAdmin = await User.findOne({
username: request.user.username,
});
//for debuggling purpose
console.log(CheckUsersIsAdmin);

//if user is not the admin respond with status - 403 -user restrictions
if (!CheckUsersIsAdmin.isAdmin) {
console.log("listing events");
//if the user is not an admin then rendering back the client side views
next();
} else {
//debugging purposes
//console.log("only for admins");
response.redirect("/api/admin-users-portal");
}
response.redirect("/api/admin-users-portal");
};
18 changes: 7 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"express": "^4.17.1",
"joi": "^17.4.2",
"jsonwebtoken": "^8.5.1",
"lodash": "^1.3.1",
"lodash": "^4.17.21",
"mongoose": "^5.13.5"
},
"devDependencies": {
Expand Down
15 changes: 10 additions & 5 deletions routes/EventCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ router.get(
"/",
[AuthenticateUser, RedirectAdminUser],
async (request, response) => {
const AllActiveEvents = await Events.find();
response
.status(200)
.send(
_.pick(AllActiveEvents, ["_id", "Title", "OrganizingClub", "Date"])
const AllActiveEvents = await Events.find({});
//for debugging purposes
console.log(AllActiveEvents);
var cardViewOutput = [];
AllActiveEvents.forEach((event) => {
cardViewOutput.push(
_.pick(event, ["_id", "Title", "OrganizingClub", "Date"])
);
});
console.log(cardViewOutput);
response.status(200).send(cardViewOutput);
}
);

Expand Down

0 comments on commit 10b54cf

Please sign in to comment.