owltide/server/utils/schedule.ts

22 lines
694 B
TypeScript
Raw Normal View History

2025-03-07 22:28:55 +01:00
import { Account } from '~/shared/types/account';
import { readSchedule, writeSchedule } from '~/server/database';
import { broadcastUpdate } from '~/server/streams';
export async function updateScheduleInterestedCounts(accounts: Account[]) {
const counts = new Map();
for (const account of accounts)
if (account.interestedIds)
for (const id of account.interestedIds)
counts.set(id, (counts.get(id) ?? 0) + 1);
const schedule = await readSchedule();
for (const event of schedule.events) {
event.interested = counts.get(event.id);
for (const slot of event.slots) {
slot.interested = counts.get(slot.id);
}
}
await writeSchedule(schedule);
broadcastUpdate(schedule);
}