* Automaticly fixable eslint issues, mostly 3 -> 2 space indentation * fix: updated plex_userid to camelcase * Linted and some consistency refactor on middleware * eslint uses ecmaversion 2020 & allow empty catch rule * Started linting source files * Fixed eslint errors & improved a lot of error handling * Set 2 eslint rules as warning temporarly
32 lines
707 B
JavaScript
32 lines
707 B
JavaScript
const establishedDatabase = require("../../database/database");
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
const mustBeAdmin = (req, res, next) => {
|
|
const database = establishedDatabase;
|
|
|
|
if (req.loggedInUser === undefined) {
|
|
res.status(401).send({
|
|
success: false,
|
|
message: "You must be logged in."
|
|
});
|
|
}
|
|
|
|
database
|
|
.get(
|
|
`SELECT admin FROM user WHERE user_name IS ?`,
|
|
req.loggedInUser.username
|
|
)
|
|
.then(isAdmin => {
|
|
if (isAdmin.admin === 0) {
|
|
return res.status(401).send({
|
|
success: false,
|
|
message: "You must be logged in as a admin."
|
|
});
|
|
}
|
|
|
|
return next();
|
|
});
|
|
};
|
|
|
|
module.exports = mustBeAdmin;
|