diff options
| author | Pitu <[email protected]> | 2019-02-26 22:26:18 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2019-02-26 22:26:18 +0900 |
| commit | 80732ff90ad8dd0aebc986816f0afd87aecc4ffa (patch) | |
| tree | 1c301e4185403d7eee469d0a2c07842ed38dbfdb /src/api/routes/admin/userPromote.js | |
| parent | Settings page and other things (diff) | |
| download | host.fuwn.me-80732ff90ad8dd0aebc986816f0afd87aecc4ffa.tar.xz host.fuwn.me-80732ff90ad8dd0aebc986816f0afd87aecc4ffa.zip | |
User promotion/demotion
Diffstat (limited to 'src/api/routes/admin/userPromote.js')
| -rw-r--r-- | src/api/routes/admin/userPromote.js | 27 |
1 files changed, 27 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..caae176 --- /dev/null +++ b/src/api/routes/admin/userPromote.js @@ -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; |