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>
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
// Duenner Client fuer MET-03s Backend-Voraussetzung
|
|
// (dms/internal/bulkeditapi) — enthaelt keine eigene Massenbearbeitungslogik.
|
|
|
|
function apiBase(): string {
|
|
const base = process.env.NEXT_PUBLIC_BULK_EDIT_API_URL;
|
|
if (!base) {
|
|
throw new Error("NEXT_PUBLIC_BULK_EDIT_API_URL ist nicht gesetzt (Umgebungsvariable erforderlich)");
|
|
}
|
|
return base;
|
|
}
|
|
|
|
function caller(): string {
|
|
const c = process.env.NEXT_PUBLIC_USER_ID;
|
|
if (!c) {
|
|
throw new Error("NEXT_PUBLIC_USER_ID ist nicht gesetzt (Umgebungsvariable erforderlich)");
|
|
}
|
|
return c;
|
|
}
|
|
|
|
export interface MetadataChange {
|
|
field_id: string;
|
|
value: string | null;
|
|
}
|
|
|
|
export interface BulkEditRequest {
|
|
documentIds: string[];
|
|
addTagIds?: string[];
|
|
removeTagIds?: string[];
|
|
metadataChanges?: MetadataChange[];
|
|
}
|
|
|
|
export interface SkippedDocument {
|
|
document_id: string;
|
|
reason: string;
|
|
}
|
|
|
|
export interface BulkEditResult {
|
|
applied: string[];
|
|
skipped: SkippedDocument[];
|
|
}
|
|
|
|
export async function applyBulkEdit(req: BulkEditRequest): Promise<BulkEditResult> {
|
|
const res = await fetch(`${apiBase()}/bulk-edit`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
actor: caller(),
|
|
document_ids: req.documentIds,
|
|
add_tag_ids: req.addTagIds ?? [],
|
|
remove_tag_ids: req.removeTagIds ?? [],
|
|
metadata_changes: req.metadataChanges ?? [],
|
|
}),
|
|
});
|
|
if (!res.ok) throw new Error(`Massenbearbeitung fehlgeschlagen (${res.status})`);
|
|
return res.json();
|
|
}
|