1
0
Fork 0

feat: Schadensbeschreibung durchreichen, Unterschrift-URL-Helfer ergaenzen

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Jonny 2026-09-03 12:31:14 +02:00
parent 9ea5e5899f
commit b0331790a4
2 changed files with 50 additions and 14 deletions

View File

@ -4,8 +4,8 @@ import { sortiereUndBeschrifteFotos } from "./fotos";
describe("sortiereUndBeschrifteFotos", () => { describe("sortiereUndBeschrifteFotos", () => {
it("sortiert Pflichtfotos in der festen Positions-Reihenfolge, unabhaengig von der Eingabe-Reihenfolge", () => { it("sortiert Pflichtfotos in der festen Positions-Reihenfolge, unabhaengig von der Eingabe-Reihenfolge", () => {
const fotos = [ const fotos = [
{ position: "heck", storage_path: "a/heck.jpg", uploaded_at: "2026-01-01T10: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" }, { position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null },
]; ];
const result = sortiereUndBeschrifteFotos(fotos); const result = sortiereUndBeschrifteFotos(fotos);
expect(result.map((f) => f.position)).toEqual(["front", "heck"]); expect(result.map((f) => f.position)).toEqual(["front", "heck"]);
@ -13,29 +13,29 @@ describe("sortiereUndBeschrifteFotos", () => {
it("beschriftet Pflichtfotos mit Leerzeichen statt Unterstrich", () => { it("beschriftet Pflichtfotos mit Leerzeichen statt Unterstrich", () => {
const fotos = [ 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); const result = sortiereUndBeschrifteFotos(fotos);
expect(result[0].label).toBe("seitlich rechts"); expect(result[0].label).toBe("seitlich rechts");
}); });
it("laesst fehlende Pflicht-Positionen einfach weg", () => { 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); const result = sortiereUndBeschrifteFotos(fotos);
expect(result).toHaveLength(1); expect(result).toHaveLength(1);
expect(result[0].position).toBe("front"); expect(result[0].position).toBe("front");
}); });
it("beschriftet ein einzelnes Schadensfoto ohne Nummer", () => { 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); const result = sortiereUndBeschrifteFotos(fotos);
expect(result[0].label).toBe("Schaden"); expect(result[0].label).toBe("Schaden");
}); });
it("nummeriert mehrere Schadensfotos nach Upload-Zeitpunkt, unabhaengig von der Eingabe-Reihenfolge", () => { it("nummeriert mehrere Schadensfotos nach Upload-Zeitpunkt, unabhaengig von der Eingabe-Reihenfolge", () => {
const fotos = [ const fotos = [
{ position: "schaden", storage_path: "a/schaden-2.jpg", uploaded_at: "2026-01-01T10: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" }, { position: "schaden", storage_path: "a/schaden-1.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null },
]; ];
const result = sortiereUndBeschrifteFotos(fotos); const result = sortiereUndBeschrifteFotos(fotos);
expect(result.map((f) => f.storage_path)).toEqual(["a/schaden-1.jpg", "a/schaden-2.jpg"]); 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", () => { it("stellt Pflichtfotos vor Schadensfotos, unabhaengig von der Eingabe-Reihenfolge", () => {
const fotos = [ const fotos = [
{ position: "schaden", storage_path: "a/schaden.jpg", uploaded_at: "2026-01-01T08: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" }, { position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null },
]; ];
const result = sortiereUndBeschrifteFotos(fotos); const result = sortiereUndBeschrifteFotos(fotos);
expect(result.map((f) => f.position)).toEqual(["front", "schaden"]); 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");
});
}); });

View File

@ -6,12 +6,14 @@ export type AuftragFoto = {
label: string; label: string;
url: string; url: string;
downloadUrl: string; downloadUrl: string;
beschreibung: string | null;
}; };
export type FotoZeile = { export type FotoZeile = {
position: string; position: string;
storage_path: string; storage_path: string;
uploaded_at: string; uploaded_at: string;
beschreibung: string | null;
}; };
export function sortiereUndBeschrifteFotos(fotos: FotoZeile[]): (FotoZeile & { label: string })[] { export function sortiereUndBeschrifteFotos(fotos: FotoZeile[]): (FotoZeile & { label: string })[] {
@ -36,11 +38,22 @@ export function sortiereUndBeschrifteFotos(fotos: FotoZeile[]): (FotoZeile & { l
return [...beschriftetePflichtFotos, ...beschrifteteSchadenFotos]; 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<AuftragFoto[]> { export async function loadAuftragFotos(auftragId: string): Promise<AuftragFoto[]> {
const supabase = await createClient(); const supabase = await createClient();
const { data } = await supabase const { data } = await supabase
.from("auftrag_fotos") .from("auftrag_fotos")
.select("position, storage_path, uploaded_at") .select("position, storage_path, uploaded_at, beschreibung")
.eq("auftrag_id", auftragId); .eq("auftrag_id", auftragId);
if (!data || data.length === 0) { if (!data || data.length === 0) {
@ -48,7 +61,6 @@ export async function loadAuftragFotos(auftragId: string): Promise<AuftragFoto[]
} }
const sortiert = sortiereUndBeschrifteFotos(data); const sortiert = sortiereUndBeschrifteFotos(data);
const publicUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
const fotos = await Promise.all( const fotos = await Promise.all(
sortiert.map(async (foto): Promise<AuftragFoto | null> => { sortiert.map(async (foto): Promise<AuftragFoto | null> => {
@ -59,14 +71,30 @@ export async function loadAuftragFotos(auftragId: string): Promise<AuftragFoto[]
return null; return null;
} }
const geparst = new URL(signiert.signedUrl); const url = toPublicUrl(signiert.signedUrl);
const url = `${publicUrl}${geparst.pathname}${geparst.search}`;
const dateiname = foto.storage_path.split("/").pop() ?? `${foto.position}.jpg`; const dateiname = foto.storage_path.split("/").pop() ?? `${foto.position}.jpg`;
const downloadUrl = `${url}&download=${encodeURIComponent(dateiname)}`; const downloadUrl = `${url}&download=${encodeURIComponent(dateiname)}`;
return { position: foto.position, label: foto.label, url, downloadUrl }; return { position: foto.position, label: foto.label, url, downloadUrl, beschreibung: foto.beschreibung };
}) })
); );
return fotos.filter((foto): foto is AuftragFoto => foto !== null); return fotos.filter((foto): foto is AuftragFoto => 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<string | null> {
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);
}