metadataapi/tagapi/bulkeditapi als Backend-Voraussetzung. MetadataForm passt sich der Felddefinition an und warnt vor Verwerfen ungespeicherter Aenderungen, TagInput schlaegt Tags vor und ist per Pfeiltasten/Enter bedienbar, Massenbearbeitung wendet Tags auf beliebig grosse Auswahlen in einem Aufruf an. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
// Duenner Client fuer MET-03s Backend-Voraussetzung (dms/internal/metadataapi)
|
|
// — enthaelt keine eigene Validierungs-/Formularlogik.
|
|
|
|
function apiBase(): string {
|
|
const base = process.env.NEXT_PUBLIC_METADATA_API_URL;
|
|
if (!base) {
|
|
throw new Error("NEXT_PUBLIC_METADATA_API_URL ist nicht gesetzt (Umgebungsvariable erforderlich)");
|
|
}
|
|
return base;
|
|
}
|
|
|
|
export interface FieldDTO {
|
|
id: string;
|
|
key: string;
|
|
label: string;
|
|
type: "text" | "number" | "date" | "bool" | "select";
|
|
required: boolean;
|
|
default_value: string | null;
|
|
}
|
|
|
|
export async function fetchFields(): Promise<FieldDTO[]> {
|
|
const res = await fetch(`${apiBase()}/metadata-fields`);
|
|
if (!res.ok) throw new Error(`Felddefinitionen konnten nicht geladen werden (${res.status})`);
|
|
return res.json();
|
|
}
|
|
|
|
export async function fetchValues(documentId: string): Promise<Record<string, string>> {
|
|
const res = await fetch(`${apiBase()}/documents/${encodeURIComponent(documentId)}/metadata`);
|
|
if (!res.ok) throw new Error(`Metadatenwerte konnten nicht geladen werden (${res.status})`);
|
|
return res.json();
|
|
}
|
|
|
|
export async function saveValues(documentId: string, values: Record<string, string>): Promise<void> {
|
|
const res = await fetch(`${apiBase()}/documents/${encodeURIComponent(documentId)}/metadata`, {
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(values),
|
|
});
|
|
if (!res.ok) {
|
|
if (res.status === 422) {
|
|
const body = await res.json().catch(() => ({}));
|
|
throw new Error(body.error ?? "Ungültiger Wert.");
|
|
}
|
|
throw new Error(`Speichern fehlgeschlagen (${res.status})`);
|
|
}
|
|
}
|