26 lines
646 B
TypeScript
26 lines
646 B
TypeScript
export interface InspectionOccupant {
|
|
occupancyId: number;
|
|
inspectionStatus?: 'present' | 'absent' | null;
|
|
}
|
|
|
|
export function getInitialPresentOccupancyIds(
|
|
occupants: InspectionOccupant[],
|
|
submitted: boolean,
|
|
): number[] {
|
|
if (!submitted) return [];
|
|
return occupants
|
|
.filter((occupant) => occupant.inspectionStatus === 'present')
|
|
.map((occupant) => occupant.occupancyId);
|
|
}
|
|
|
|
export function togglePresentOccupancy(
|
|
currentIds: number[],
|
|
occupancyId: number,
|
|
present: boolean,
|
|
): number[] {
|
|
const next = new Set(currentIds);
|
|
if (present) next.add(occupancyId);
|
|
else next.delete(occupancyId);
|
|
return [...next];
|
|
}
|