import { Account } from '~/shared/types/account'; import { Schedule } from '~/shared/types/schedule'; 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); await broadcastUpdate(schedule); } export function canSeeCrew(accountType: string | undefined) { return accountType === "crew" || accountType === "admin"; } /** Filters out crew visible only parts of schedule */ export function filterSchedule(schedule: Schedule): Schedule { return { locations: schedule.locations, events: schedule.events .filter(event => !event.crew) .map(event => ({ ...event, slots: event.slots.map(slot => ({ ...slot, assigned: undefined, }), }), } }