User promotion/demotion
This commit is contained in:
parent
8be134c8d8
commit
80732ff90a
|
@ -0,0 +1,27 @@
|
|||
const Route = require('../../structures/Route');
|
||||
|
||||
class userDemote extends Route {
|
||||
constructor() {
|
||||
super('/admin/users/demote', 'get', { adminOnly: true });
|
||||
}
|
||||
|
||||
async run(req, res, db) {
|
||||
if (!req.body) return res.status(400).json({ message: 'No body provided' });
|
||||
const { id } = req.body;
|
||||
if (!id) return res.status(400).json({ message: 'No name provided' });
|
||||
|
||||
try {
|
||||
await db.table('users')
|
||||
.where({ id })
|
||||
.update({ isAdmin: false });
|
||||
} catch (error) {
|
||||
return super.error(res, error);
|
||||
}
|
||||
|
||||
return res.json({
|
||||
message: 'Successfully promoted user'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = userDemote;
|
|
@ -0,0 +1,27 @@
|
|||
const Route = require('../../structures/Route');
|
||||
|
||||
class userPromote extends Route {
|
||||
constructor() {
|
||||
super('/admin/users/promote', 'get', { adminOnly: true });
|
||||
}
|
||||
|
||||
async run(req, res, db) {
|
||||
if (!req.body) return res.status(400).json({ message: 'No body provided' });
|
||||
const { id } = req.body;
|
||||
if (!id) return res.status(400).json({ message: 'No name provided' });
|
||||
|
||||
try {
|
||||
await db.table('users')
|
||||
.where({ id })
|
||||
.update({ isAdmin: true });
|
||||
} catch (error) {
|
||||
return super.error(res, error);
|
||||
}
|
||||
|
||||
return res.json({
|
||||
message: 'Successfully promoted user'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = userPromote;
|
|
@ -0,0 +1,23 @@
|
|||
const Route = require('../../structures/Route');
|
||||
|
||||
class usersGET extends Route {
|
||||
constructor() {
|
||||
super('/admin/users', 'get', { adminOnly: true });
|
||||
}
|
||||
|
||||
async run(req, res, db) {
|
||||
try {
|
||||
const users = await db.table('users')
|
||||
.select('id', 'username', 'enabled', 'isAdmin', 'createdAt');
|
||||
|
||||
return res.json({
|
||||
message: 'Successfully retrieved users',
|
||||
users
|
||||
});
|
||||
} catch (error) {
|
||||
return super.error(res, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = usersGET;
|
Loading…
Reference in New Issue