forked from fahrPool/fahrPool
25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
// Nutzer je Rolle einer Firma, Grundlage fuer die rollenabhaengige Abrechnung.
|
|
// Gezaehlt werden alle angelegten Profile, auch gesperrte.
|
|
export type RollenAnzahl = { admin: number; disponent: number; fahrer: number; readonly: number };
|
|
|
|
const ROLLEN = ["admin", "disponent", "fahrer", "readonly"] as const;
|
|
|
|
const BESCHRIFTUNG: Record<keyof RollenAnzahl, [einzahl: string, mehrzahl: string]> = {
|
|
admin: ["Admin", "Admins"],
|
|
disponent: ["Disponent", "Disponenten"],
|
|
fahrer: ["Fahrer", "Fahrer"],
|
|
readonly: ["ReadOnly", "ReadOnly"],
|
|
};
|
|
|
|
export function zaehleRollen(profile: { role: string | null }[] | null | undefined): RollenAnzahl {
|
|
const anzahl: RollenAnzahl = { admin: 0, disponent: 0, fahrer: 0, readonly: 0 };
|
|
for (const p of profile ?? []) {
|
|
if ((ROLLEN as readonly string[]).includes(p.role ?? "")) anzahl[p.role as keyof RollenAnzahl]++;
|
|
}
|
|
return anzahl;
|
|
}
|
|
|
|
export function formatiereRollen(a: RollenAnzahl): string {
|
|
return ROLLEN.map((r) => `${a[r]} ${BESCHRIFTUNG[r][a[r] === 1 ? 0 : 1]}`).join(" · ");
|
|
}
|