Started working on the admin panel

This commit is contained in:
2021-01-31 12:07:03 +11:00
parent 71f3f8e370
commit be89c2d8d9
14 changed files with 202 additions and 6 deletions
View File
+39
View File
@@ -0,0 +1,39 @@
const { Op } = require('sequelize');
const { bannedEmails, accounts } = require('../database/models');
const route = async (req, res) => {
//make sure the account is an admin
if (req.cookies['admin'] !== process.env.SESSION_ADMIN) {
return res.status(401).send('invalid admin status');
}
//merge the banned accounts with the account data, if any
const data = await bannedEmails.findAll()
.then(bans => bans.map(async ban => {
//find a matching account
const account = await accounts.findOne({
attrubutes: ['username', 'privilege'],
where: {
email: {
[Op.eq]: ban.email
}
}
}) || {};
//merge the data and return (becomes a promise)
return {
username: account.username,
email: ban.email,
privilege: account.privilege,
expiry: ban.expiry,
reason: ban.reason
};
}))
.then(promises => Promise.all(promises)) //resolve promises
.catch(e => console.error(e))
;
res.status(200).json(data);
};
module.exports = route;
+9
View File
@@ -0,0 +1,9 @@
const express = require('express');
const router = express.Router();
//basic account management
router.post('/banned', require('./banned'));
//router.post('/ban', require('./ban'));
//router.post('/unban', require('./unban'));
module.exports = router;
View File