aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/admin/userDisable.js
blob: a3dbb15f38709827623ebaa0102593745ecd8845 (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
28
29
const Route = require('../../structures/Route');

class userDisable extends Route {
	constructor() {
		super('/admin/users/disable', '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({ enabled: false })
				.wasMutated();
		} catch (error) {
			return super.error(res, error);
		}

		return res.json({
			message: 'Successfully disabled user'
		});
	}
}

module.exports = userDisable;