2025-03-07 22:28:55 +01:00
|
|
|
import { Account } from '~/shared/types/account';
|
2025-03-10 16:26:52 +01:00
|
|
|
import { Schedule } from '~/shared/types/schedule';
|
2025-03-07 22:28:55 +01:00
|
|
|
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);
|
2025-03-10 16:26:52 +01:00
|
|
|
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),
|
|
|
|
}
|
2025-03-07 22:28:55 +01:00
|
|
|
}
|