aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/admin/userDemote.js
blob: e9c37a073988f51447fbe34ac9be9d4f6ca4e0a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;