summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/admin/invite.ts
blob: 987105791f5670a0fd45691f9dd4ab77b7c990c4 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import rndstr from 'rndstr';
import define from '../../define';
import { RegistrationTickets } from '../../../../models';
import { genId } from '../../../../misc/gen-id';

export const meta = {
	desc: {
		'ja-JP': '招待コードを発行します。',
		'en-US': 'Issue an invitation code.'
	},

	tags: ['admin'],

	requireCredential: true as const,
	requireModerator: true,

	params: {},

	res: {
		type: 'object' as const,
		optional: false as const, nullable: false as const,
		properties: {
			code: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'Give this code to the applicant for registration.',
				example: '2ERUA5VR',
				maxLength: 8,
				minLength: 8
			}
		}
	}
};

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.insert({
		id: genId(),
		createdAt: new Date(),
		code,
	});

	return {
		code,
	};
});