/
checkin.ts
34 lines (29 loc) · 1008 Bytes
/
checkin.ts
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 { CHECKIN_COMMAND_NAME } from "../../constants";
import { buildCheckinModalResponse } from "../../responses/checkinCommandResponse";
import { Repositories } from "../../types";
import { ApplicationCommandObj } from "../handleApplicationCommands";
const handler = async ({
intentObj,
repositories: { usersRepository, eventsRepository },
}: {
intentObj: ApplicationCommandObj;
repositories: Repositories;
}) => {
if (!intentObj.member) {
throw new Error("Invalid interaction");
}
const todayEvent = await eventsRepository.findTodayEvent();
if (!todayEvent) {
throw new Error(
"もくもく会が開始されていません。チェックインの前に`/mokumoku-start`を実行してください。",
);
}
const prevCheckin = await usersRepository.findLatestCheckinByDiscordUserId(
intentObj.member.user.id,
);
return buildCheckinModalResponse(prevCheckin?.profile ?? undefined);
};
export default {
commandName: CHECKIN_COMMAND_NAME,
handler,
};