aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/user/apiKey.js
blob: 820e28cb369103ac61376f6529ae4ebf55ed9f88 (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');
const randomstring = require('randomstring');
const moment = require('moment');

class apiKeyPOST extends Route {
	constructor() {
		super('/user/apikey/change', 'post');
	}

	async run(req, res, db, user) {
		const now = moment.utc().toDate();
		const apiKey = randomstring.generate(64);
		await db.table('users')
			.where({ id: user.id })
			.update({
				apiKey,
				apiKeyEditedAt: now
			});

		return res.json({
			message: 'Successfully created new api key',
			apiKey
		});
	}
}

module.exports = apiKeyPOST;