fahrPool/web/lib/dashboard/einsatz-personen.ts

12 lines
455 B
TypeScript

import type { Role } from "@/lib/auth/roles";
export type EinsatzPerson = { id: string; name: string; role: Role };
const ROLLEN_RANG: Partial<Record<Role, number>> = { fahrer: 0, disponent: 1, admin: 2 };
export function sortiereEinsatzPersonen<T extends { name: string; role: Role }>(personen: T[]): T[] {
return [...personen].sort(
(a, b) => (ROLLEN_RANG[a.role] ?? 9) - (ROLLEN_RANG[b.role] ?? 9) || a.name.localeCompare(b.name, "de")
);
}