22 lines
694 B
TypeScript
22 lines
694 B
TypeScript
|
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);
|
||
|
}
|