From 76c555a292434b8dafbf92441667a1e0582e00ad Mon Sep 17 00:00:00 2001 From: Jonny Date: Tue, 18 Aug 2026 15:05:27 +0200 Subject: [PATCH] feat: make Fahrtbeginn photos optional, rename PFLICHT_FOTO_POSITIONEN to STANDARD_FOTO_POSITIONEN --- web/lib/auftraege/foto-positionen.ts | 4 ++-- web/lib/auftraege/fotos.ts | 4 ++-- web/lib/auftraege/validate-fahrt.test.ts | 30 ++++-------------------- web/lib/auftraege/validate-fahrt.ts | 16 +------------ 4 files changed, 9 insertions(+), 45 deletions(-) diff --git a/web/lib/auftraege/foto-positionen.ts b/web/lib/auftraege/foto-positionen.ts index 9201ea2..87b16cf 100644 --- a/web/lib/auftraege/foto-positionen.ts +++ b/web/lib/auftraege/foto-positionen.ts @@ -1,4 +1,4 @@ -export const PFLICHT_FOTO_POSITIONEN = [ +export const STANDARD_FOTO_POSITIONEN = [ "front", "seitlich_rechts", "rechte_seite", @@ -9,4 +9,4 @@ export const PFLICHT_FOTO_POSITIONEN = [ "seitlich_vorne_links", ] as const; -export type PflichtFotoPosition = (typeof PFLICHT_FOTO_POSITIONEN)[number]; +export type StandardFotoPosition = (typeof STANDARD_FOTO_POSITIONEN)[number]; diff --git a/web/lib/auftraege/fotos.ts b/web/lib/auftraege/fotos.ts index e40dc59..5e060c6 100644 --- a/web/lib/auftraege/fotos.ts +++ b/web/lib/auftraege/fotos.ts @@ -1,5 +1,5 @@ import { createClient } from "@/lib/supabase/server"; -import { PFLICHT_FOTO_POSITIONEN } from "./foto-positionen"; +import { STANDARD_FOTO_POSITIONEN } from "./foto-positionen"; export type AuftragFoto = { position: string; @@ -15,7 +15,7 @@ export type FotoZeile = { }; export function sortiereUndBeschrifteFotos(fotos: FotoZeile[]): (FotoZeile & { label: string })[] { - const pflichtFotos = PFLICHT_FOTO_POSITIONEN.map((position) => + const pflichtFotos = STANDARD_FOTO_POSITIONEN.map((position) => fotos.find((foto) => foto.position === position) ).filter((foto): foto is FotoZeile => foto !== undefined); diff --git a/web/lib/auftraege/validate-fahrt.test.ts b/web/lib/auftraege/validate-fahrt.test.ts index afa1fa1..8993bf8 100644 --- a/web/lib/auftraege/validate-fahrt.test.ts +++ b/web/lib/auftraege/validate-fahrt.test.ts @@ -1,43 +1,21 @@ import { describe, expect, it } from "vitest"; import { validateFahrtBeginn, validateFahrtEnde } from "./validate-fahrt"; -import { PFLICHT_FOTO_POSITIONEN } from "./foto-positionen"; describe("validateFahrtBeginn", () => { - it("akzeptiert gueltigen KM-Stand mit allen 8 Pflichtfotos", () => { - const result = validateFahrtBeginn({ - startKm: "12345", - vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN], - }); + it("akzeptiert einen gueltigen KM-Stand", () => { + const result = validateFahrtBeginn({ startKm: "12345" }); expect(result).toEqual({ valid: true, startKm: 12345 }); }); it("lehnt einen fehlenden KM-Stand ab", () => { - const result = validateFahrtBeginn({ - startKm: "", - vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN], - }); + const result = validateFahrtBeginn({ startKm: "" }); expect(result).toEqual({ valid: false, error: "Bitte einen KM-Stand eingeben." }); }); it("lehnt einen negativen KM-Stand ab", () => { - const result = validateFahrtBeginn({ - startKm: "-5", - vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN], - }); + const result = validateFahrtBeginn({ startKm: "-5" }); expect(result).toEqual({ valid: false, error: "Der KM-Stand darf nicht negativ sein." }); }); - - it("lehnt fehlende Pflichtfotos ab und benennt die fehlenden Positionen", () => { - const result = validateFahrtBeginn({ - startKm: "12345", - vorhandenePositionen: ["front", "heck"], - }); - expect(result).toEqual({ - valid: false, - error: - "Es fehlen noch 6 Pflichtfoto(s): seitlich_rechts, rechte_seite, seitlich_rechts_heck, seitlich_links_heck, linke_seite, seitlich_vorne_links", - }); - }); }); describe("validateFahrtEnde", () => { diff --git a/web/lib/auftraege/validate-fahrt.ts b/web/lib/auftraege/validate-fahrt.ts index 1a80b3e..03ff491 100644 --- a/web/lib/auftraege/validate-fahrt.ts +++ b/web/lib/auftraege/validate-fahrt.ts @@ -1,5 +1,3 @@ -import { PFLICHT_FOTO_POSITIONEN } from "./foto-positionen"; - export type FahrtBeginnValidationResult = | { valid: true; startKm: number } | { valid: false; error: string }; @@ -16,10 +14,7 @@ function parseKm(value: FormDataEntryValue | null): number | null { return Number.isFinite(parsed) ? parsed : null; } -export function validateFahrtBeginn(input: { - startKm: FormDataEntryValue | null; - vorhandenePositionen: string[]; -}): FahrtBeginnValidationResult { +export function validateFahrtBeginn(input: { startKm: FormDataEntryValue | null }): FahrtBeginnValidationResult { const startKm = parseKm(input.startKm); if (startKm === null) { return { valid: false, error: "Bitte einen KM-Stand eingeben." }; @@ -28,15 +23,6 @@ export function validateFahrtBeginn(input: { return { valid: false, error: "Der KM-Stand darf nicht negativ sein." }; } - const vorhanden = new Set(input.vorhandenePositionen); - const fehlend = PFLICHT_FOTO_POSITIONEN.filter((position) => !vorhanden.has(position)); - if (fehlend.length > 0) { - return { - valid: false, - error: `Es fehlen noch ${fehlend.length} Pflichtfoto(s): ${fehlend.join(", ")}`, - }; - } - return { valid: true, startKm }; }