From b0331790a496cb6e228916fa32d27a326033b2d0 Mon Sep 17 00:00:00 2001 From: Jonny Date: Thu, 3 Sep 2026 12:31:14 +0200 Subject: [PATCH] feat: Schadensbeschreibung durchreichen, Unterschrift-URL-Helfer ergaenzen Co-Authored-By: Claude Sonnet 5 --- web/lib/auftraege/fotos.test.ts | 26 ++++++++++++++-------- web/lib/auftraege/fotos.ts | 38 ++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/web/lib/auftraege/fotos.test.ts b/web/lib/auftraege/fotos.test.ts index bf99487..850d6b4 100644 --- a/web/lib/auftraege/fotos.test.ts +++ b/web/lib/auftraege/fotos.test.ts @@ -4,8 +4,8 @@ import { sortiereUndBeschrifteFotos } from "./fotos"; describe("sortiereUndBeschrifteFotos", () => { it("sortiert Pflichtfotos in der festen Positions-Reihenfolge, unabhaengig von der Eingabe-Reihenfolge", () => { const fotos = [ - { position: "heck", storage_path: "a/heck.jpg", uploaded_at: "2026-01-01T10:00:00Z" }, - { position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z" }, + { position: "heck", storage_path: "a/heck.jpg", uploaded_at: "2026-01-01T10:00:00Z", beschreibung: null }, + { position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null }, ]; const result = sortiereUndBeschrifteFotos(fotos); expect(result.map((f) => f.position)).toEqual(["front", "heck"]); @@ -13,29 +13,29 @@ describe("sortiereUndBeschrifteFotos", () => { it("beschriftet Pflichtfotos mit Leerzeichen statt Unterstrich", () => { const fotos = [ - { position: "seitlich_rechts", storage_path: "a/seitlich_rechts.jpg", uploaded_at: "2026-01-01T09:00:00Z" }, + { position: "seitlich_rechts", storage_path: "a/seitlich_rechts.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null }, ]; const result = sortiereUndBeschrifteFotos(fotos); expect(result[0].label).toBe("seitlich rechts"); }); it("laesst fehlende Pflicht-Positionen einfach weg", () => { - const fotos = [{ position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z" }]; + const fotos = [{ position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null }]; const result = sortiereUndBeschrifteFotos(fotos); expect(result).toHaveLength(1); expect(result[0].position).toBe("front"); }); it("beschriftet ein einzelnes Schadensfoto ohne Nummer", () => { - const fotos = [{ position: "schaden", storage_path: "a/schaden-1.jpg", uploaded_at: "2026-01-01T09:00:00Z" }]; + const fotos = [{ position: "schaden", storage_path: "a/schaden-1.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null }]; const result = sortiereUndBeschrifteFotos(fotos); expect(result[0].label).toBe("Schaden"); }); it("nummeriert mehrere Schadensfotos nach Upload-Zeitpunkt, unabhaengig von der Eingabe-Reihenfolge", () => { const fotos = [ - { position: "schaden", storage_path: "a/schaden-2.jpg", uploaded_at: "2026-01-01T10:00:00Z" }, - { position: "schaden", storage_path: "a/schaden-1.jpg", uploaded_at: "2026-01-01T09:00:00Z" }, + { position: "schaden", storage_path: "a/schaden-2.jpg", uploaded_at: "2026-01-01T10:00:00Z", beschreibung: null }, + { position: "schaden", storage_path: "a/schaden-1.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null }, ]; const result = sortiereUndBeschrifteFotos(fotos); expect(result.map((f) => f.storage_path)).toEqual(["a/schaden-1.jpg", "a/schaden-2.jpg"]); @@ -44,10 +44,18 @@ describe("sortiereUndBeschrifteFotos", () => { it("stellt Pflichtfotos vor Schadensfotos, unabhaengig von der Eingabe-Reihenfolge", () => { const fotos = [ - { position: "schaden", storage_path: "a/schaden.jpg", uploaded_at: "2026-01-01T08:00:00Z" }, - { position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z" }, + { position: "schaden", storage_path: "a/schaden.jpg", uploaded_at: "2026-01-01T08:00:00Z", beschreibung: null }, + { position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null }, ]; const result = sortiereUndBeschrifteFotos(fotos); expect(result.map((f) => f.position)).toEqual(["front", "schaden"]); }); + + it("reicht die Schadensbeschreibung unveraendert durch", () => { + const fotos = [ + { position: "schaden", storage_path: "a/schaden-1.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: "Kratzer hintere Stossstange" }, + ]; + const result = sortiereUndBeschrifteFotos(fotos); + expect(result[0].beschreibung).toBe("Kratzer hintere Stossstange"); + }); }); diff --git a/web/lib/auftraege/fotos.ts b/web/lib/auftraege/fotos.ts index 5e060c6..bbdf14f 100644 --- a/web/lib/auftraege/fotos.ts +++ b/web/lib/auftraege/fotos.ts @@ -6,12 +6,14 @@ export type AuftragFoto = { label: string; url: string; downloadUrl: string; + beschreibung: string | null; }; export type FotoZeile = { position: string; storage_path: string; uploaded_at: string; + beschreibung: string | null; }; export function sortiereUndBeschrifteFotos(fotos: FotoZeile[]): (FotoZeile & { label: string })[] { @@ -36,11 +38,22 @@ export function sortiereUndBeschrifteFotos(fotos: FotoZeile[]): (FotoZeile & { l return [...beschriftetePflichtFotos, ...beschrifteteSchadenFotos]; } +// Baut aus einer von Supabase Storage signierten URL (die auf die +// interne/Docker-Kong-Basis zeigen kann, siehe +// docs/superpowers/specs/2026-08-18-auftrag-foto-galerie-design.md Abschnitt +// 2) die von aussen erreichbare oeffentliche URL, unter Beibehaltung von +// Pfad und Query-String (Signatur-Token). +function toPublicUrl(signedUrl: string): string { + const publicUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!; + const geparst = new URL(signedUrl); + return `${publicUrl}${geparst.pathname}${geparst.search}`; +} + export async function loadAuftragFotos(auftragId: string): Promise { const supabase = await createClient(); const { data } = await supabase .from("auftrag_fotos") - .select("position, storage_path, uploaded_at") + .select("position, storage_path, uploaded_at, beschreibung") .eq("auftrag_id", auftragId); if (!data || data.length === 0) { @@ -48,7 +61,6 @@ export async function loadAuftragFotos(auftragId: string): Promise => { @@ -59,14 +71,30 @@ export async function loadAuftragFotos(auftragId: string): Promise foto !== null); } + +// Signierte URL fuer die Unterschriftsgrafik eines abgeschlossenen Auftrags. +// null, wenn keine Unterschrift hochgeladen wurde (haeufigster Fall, da +// optional) oder das Signieren fehlschlaegt. +export async function loadUnterschriftUrl(storagePath: string | null): Promise { + if (!storagePath) { + return null; + } + const supabase = await createClient(); + const { data: signiert } = await supabase.storage + .from("auftrag-unterschriften") + .createSignedUrl(storagePath, 3600); + if (!signiert) { + return null; + } + return toPublicUrl(signiert.signedUrl); +}