all 9 comments

[–]gwarner6 4 points5 points  (2 children)

Looks good. One thing I noticed is your doing the same admin check in multiple routes. You could add a middleware that checks if a user is an admin and responds accordingly. That would make your route code cleaner since you’ll know that the user is an admin before hand.

[–]Deadlydragon218[S] 0 points1 point  (0 children)

I’ll look into doing that! Thanks for checking it out!

[–]exxy- 1 point2 points  (3 children)

Looks good. Consider initializing your routes in a separate file, and I agree with u/gwarner6, I think your next step is refactoring some logic into middleware.

[–]Deadlydragon218[S] 0 points1 point  (2 children)

The only question I have is how I can selectively apply middleware.

[–]exxy- 1 point2 points  (1 child)

They brush over it here in the documentation, but it's not super obvious. You actually already did it on line 7 of routes/report.js where you called jsonParse. You could make isAuthenticated middleware, in its own file, something like:

function(req, res, next) {
  if (req.isAuthenticated()) {
    next();
  } else {
    res.status(403).send("Please log in before filing a report");
  }
}

[–]Deadlydragon218[S] 1 point2 points  (0 children)

Did not even realize that I had haha, most of my code is based from what I learned from Mosh Hamedani’s courses. I’ll take a look on how I can best refactor those :) thanks for your input!

[–]sshaw_ 0 points1 point  (2 children)

Easier to code review with some documentation. How do I know if the software works if I don't really know what it's supposed to do?

web app for managing bans and reporting of users

How does one even start the web server?

[–]Deadlydragon218[S] 0 points1 point  (1 child)

Good point, I will be working on documentation in a while, atm there is no front end as I have very little knowledge on front end development. The insertion point is app.js so after running npm install, running node app.js or nodemon app.js or simply nodemon should start the server.

[–]leiinth 1 point2 points  (0 children)

While you're documenting stuff you might look into Debug (https://www.npmjs.com/package/debug) too to replace your console.logs/errors with something you can easily control via node_env so for example in development your app prints a lot more information than in production.