sendou.ink/app/routines/notifyPlusServerVoting.ts
Kalle a358606d4f
Some checks failed
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
More fixing of plus server tier resolution (pass always correct seasonNth + for ongoing season use full tiers list)
2025-03-10 22:35:03 +02:00

40 lines
1.1 KiB
TypeScript

import { currentSeason } from "../features/mmr/season";
import * as NotificationRepository from "../features/notifications/NotificationRepository.server";
import { notify } from "../features/notifications/core/notify.server";
import { isVotingActive } from "../features/plus-voting/core";
import * as UserRepository from "../features/user-page/UserRepository.server";
import { Routine } from "./routine.server";
export const NotifyPlusServerVotingRoutine = new Routine({
name: "NotifyPlusServerVoting",
func: async () => {
if (!isVotingActive()) return;
const season = currentSeason(new Date())!;
const plusVotingNotifications = await NotificationRepository.findAllByType(
"PLUS_VOTING_STARTED",
);
if (
plusVotingNotifications.some(
(notification) => notification.meta.seasonNth === season.nth,
)
) {
return;
}
await notify({
notification: {
type: "PLUS_VOTING_STARTED",
meta: {
seasonNth: season.nth,
},
},
userIds: (await UserRepository.findAllPlusServerMembers()).map(
(member) => member.userId,
),
});
},
});