forked from fahrPool/fahrPool
feat: Personenliste fuer Zuweisung und Filter umfasst alle Einsatzrollen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a538e2eddd
commit
778827fe1c
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
import { loadProfile } from "@/lib/auth/profile";
|
||||
import { kannAuftraegeVerwalten } from "@/lib/auth/roles";
|
||||
|
||||
export type MutationResult = { success: true } | { success: false; error: string };
|
||||
|
||||
|
|
@ -63,10 +64,7 @@ export async function stornierenVomBoard(auftragId: string): Promise<MutationRes
|
|||
|
||||
export async function zuweisenAnFahrer(auftragId: string, fahrerId: string): Promise<MutationResult> {
|
||||
const profileResult = await loadProfile();
|
||||
if (
|
||||
profileResult.status !== "ok" ||
|
||||
(profileResult.profile.role !== "admin" && profileResult.profile.role !== "disponent")
|
||||
) {
|
||||
if (profileResult.status !== "ok" || !kannAuftraegeVerwalten(profileResult.profile.role)) {
|
||||
return { success: false, error: "Nur Disponent/Admin duerfen Auftraege zuweisen." };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { loadProfile } from "@/lib/auth/profile";
|
||||
import { listAuftraegeFuerKanban, listFahrerNutzer } from "@/lib/dashboard/queries";
|
||||
import { listAuftraegeFuerKanban, listEinsatzPersonen } from "@/lib/dashboard/queries";
|
||||
import { kannAuftraegeVerwalten, personBezeichnung } from "@/lib/auth/roles";
|
||||
import { parseKanbanFilter } from "@/lib/dashboard/kanban-filter";
|
||||
import { InstallHinweis } from "@/components/pwa/InstallHinweis";
|
||||
import { KanbanBoard } from "@/components/dashboard/KanbanBoard";
|
||||
|
|
@ -14,10 +15,12 @@ export default async function DashboardPage({
|
|||
return null;
|
||||
}
|
||||
|
||||
const kannZuweisen = profileResult.profile.role === "admin" || profileResult.profile.role === "disponent";
|
||||
const kannZuweisen = kannAuftraegeVerwalten(profileResult.profile.role);
|
||||
const [spalten, fahrerListe, filter] = await Promise.all([
|
||||
listAuftraegeFuerKanban(),
|
||||
kannZuweisen ? listFahrerNutzer() : Promise.resolve([]),
|
||||
kannZuweisen
|
||||
? listEinsatzPersonen().then((personen) => personen.map((p) => ({ id: p.id, name: personBezeichnung(p) })))
|
||||
: Promise.resolve([]),
|
||||
searchParams.then(parseKanbanFilter),
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { redirect } from "next/navigation";
|
||||
import { loadProfile } from "@/lib/auth/profile";
|
||||
import { kannZeiterfassungNutzen } from "@/lib/auth/roles";
|
||||
import { kannZeiterfassungNutzen, personBezeichnung } from "@/lib/auth/roles";
|
||||
import {
|
||||
listSchichten,
|
||||
listOffeneSchichten,
|
||||
findeOffeneSchicht,
|
||||
findeAuftraegeInSchicht,
|
||||
} from "@/lib/zeiterfassung/queries";
|
||||
import { listFahrerNutzer } from "@/lib/dashboard/queries";
|
||||
import { listEinsatzPersonen } from "@/lib/dashboard/queries";
|
||||
import { gruppiereProTag, gruppiereProWoche } from "@/lib/zeiterfassung/aggregation";
|
||||
import { nettoMinuten, pauseMinuten } from "@/lib/zeiterfassung/zeit-berechnung";
|
||||
import { Card } from "@/components/ui/Card";
|
||||
|
|
@ -46,7 +46,9 @@ export default async function ZeiterfassungPage({
|
|||
const [schichten, offeneSchicht, fahrerListe, offeneSchichtenAlle] = await Promise.all([
|
||||
listSchichten(zeitraum, istDisponentOderAdmin ? fahrer_id : profileResult.profile.id),
|
||||
istDisponentOderAdmin ? Promise.resolve(null) : findeOffeneSchicht(profileResult.profile.id),
|
||||
istDisponentOderAdmin ? listFahrerNutzer() : Promise.resolve([]),
|
||||
istDisponentOderAdmin
|
||||
? listEinsatzPersonen().then((personen) => personen.map((p) => ({ id: p.id, name: personBezeichnung(p) })))
|
||||
: Promise.resolve([]),
|
||||
istDisponentOderAdmin ? listOffeneSchichten() : Promise.resolve([]),
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { sortiereEinsatzPersonen } from "./einsatz-personen";
|
||||
|
||||
describe("sortiereEinsatzPersonen", () => {
|
||||
it("sortiert nach Rolle (Fahrer, Disponent, Admin), dann nach Name", () => {
|
||||
const ergebnis = sortiereEinsatzPersonen([
|
||||
{ id: "1", name: "Zoe", role: "admin" },
|
||||
{ id: "2", name: "Anna", role: "disponent" },
|
||||
{ id: "3", name: "Bert", role: "fahrer" },
|
||||
{ id: "4", name: "Albert", role: "fahrer" },
|
||||
]);
|
||||
expect(ergebnis.map((p) => p.name)).toEqual(["Albert", "Bert", "Anna", "Zoe"]);
|
||||
});
|
||||
|
||||
it("vergleicht Namen deutsch (Umlaute)", () => {
|
||||
const ergebnis = sortiereEinsatzPersonen([
|
||||
{ id: "1", name: "Bert", role: "fahrer" },
|
||||
{ id: "2", name: "Ärger", role: "fahrer" },
|
||||
]);
|
||||
expect(ergebnis.map((p) => p.name)).toEqual(["Ärger", "Bert"]);
|
||||
});
|
||||
|
||||
it("veraendert die Eingabe nicht", () => {
|
||||
const eingabe = [
|
||||
{ id: "1", name: "B", role: "admin" as const },
|
||||
{ id: "2", name: "A", role: "fahrer" as const },
|
||||
];
|
||||
sortiereEinsatzPersonen(eingabe);
|
||||
expect(eingabe[0].name).toBe("B");
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
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")
|
||||
);
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import { createClient } from "@/lib/supabase/server";
|
|||
import type { AuftragStatus, Ort, Fahrzeug } from "@/lib/auftraege/queries";
|
||||
import type { FinAbgleich } from "@/lib/auftraege/fin-abgleich";
|
||||
import type { ZeitplanungTyp } from "@/lib/auftraege/zeitplanung";
|
||||
import { sortiereEinsatzPersonen, type EinsatzPerson } from "./einsatz-personen";
|
||||
|
||||
export type KanbanAuftrag = {
|
||||
id: string;
|
||||
|
|
@ -63,8 +64,11 @@ export async function listAuftraegeFuerKanban(): Promise<KanbanSpalten> {
|
|||
return spalten;
|
||||
}
|
||||
|
||||
export async function listFahrerNutzer(): Promise<{ id: string; name: string }[]> {
|
||||
export async function listEinsatzPersonen(): Promise<EinsatzPerson[]> {
|
||||
const supabase = await createClient();
|
||||
const { data } = await supabase.from("profiles").select("id, name").eq("role", "fahrer").order("name");
|
||||
return data ?? [];
|
||||
const { data } = await supabase
|
||||
.from("profiles")
|
||||
.select("id, name, role")
|
||||
.in("role", ["fahrer", "disponent", "admin"]);
|
||||
return sortiereEinsatzPersonen((data ?? []) as EinsatzPerson[]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue