aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/admin/userPromote.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/routes/admin/userPromote.js')
-rw-r--r--src/api/routes/admin/userPromote.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/api/routes/admin/userPromote.js b/src/api/routes/admin/userPromote.js
new file mode 100644
index 0000000..4a5ed88
--- /dev/null
+++ b/src/api/routes/admin/userPromote.js
@@ -0,0 +1,28 @@
+const Route = require('../../structures/Route');
+
+class userPromote extends Route {
+ constructor() {
+ super('/admin/users/promote', 'post', { adminOnly: true });
+ }
+
+ async run(req, res, db, user) {
+ 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 id provided' });
+ if (id === user.id) return res.status(400).json({ message: 'You can\'t apply this action to yourself' });
+
+ 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;