summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/admin/invite.ts
blob: 52e3da8f846c997f6ffc355d1fbdeb3efc6c566e (plain)
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
30
31
32
33
34
import rndstr from 'rndstr';
import define from '../../define';
import { RegistrationTickets } from '../../../../models';
import { genId } from '../../../../misc/gen-id';

export const meta = {
	desc: {
		'ja-JP': '招待コードを発行します。'
	},

	tags: ['admin'],

	requireCredential: true as const,
	requireModerator: true,

	params: {}
};

export default define(meta, async () => {
	const code = rndstr({
		length: 8,
		chars: '2-9A-HJ-NP-Z', // [0-9A-Z] w/o [01IO] (32 patterns)
	});

	await RegistrationTickets.save({
		id: genId(),
		createdAt: new Date(),
		code,
	});

	return {
		code,
	};
});