feat(hosts): Host-Tabelle mit Filtern, CSV-Export und Detailansicht (#007)
Suche ueber Hostname, Key, Server-ID, IP und Rechnungsnummer, fuenf Filter, Sortierung mit nulls-last, Seitenblaettern und CSV-Export. Detailansicht mit sechs Tabs, Notizen, Tags und Token-Widerruf. 59 Tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { protokolliere } from "@/server/audit";
|
||||
import type { AktionsErgebnis } from "./kunden";
|
||||
|
||||
/** Speichert Notizen und Tags eines Hosts. */
|
||||
export async function hostNotizenSpeichern(
|
||||
_vorher: AktionsErgebnis,
|
||||
formular: FormData,
|
||||
): Promise<AktionsErgebnis> {
|
||||
const hostId = formular.get("hostId")?.toString();
|
||||
if (!hostId) return { fehler: "Host nicht gefunden." };
|
||||
|
||||
const notizen = formular.get("notizen")?.toString().trim() || null;
|
||||
const tags = (formular.get("tags")?.toString() ?? "")
|
||||
.split(",")
|
||||
.map((tag) => tag.trim().toLowerCase())
|
||||
.filter(Boolean)
|
||||
.slice(0, 12);
|
||||
|
||||
await prisma.host.update({
|
||||
where: { id: hostId },
|
||||
data: {
|
||||
notizen,
|
||||
tags: {
|
||||
set: [],
|
||||
connectOrCreate: tags.map((name) => ({ where: { name }, create: { name } })),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await protokolliere("host.notizen_geaendert", "Host", hostId, { notizen, tags });
|
||||
revalidatePath(`/hosts/${hostId}`);
|
||||
|
||||
return { erfolg: "Gespeichert." };
|
||||
}
|
||||
|
||||
/** Ordnet einen einzelnen Host einem Kunden zu (aus der Detailansicht heraus). */
|
||||
export async function hostKundeSetzen(formular: FormData) {
|
||||
const hostId = formular.get("hostId")?.toString();
|
||||
const kundeId = formular.get("kundeId")?.toString() || null;
|
||||
const standortId = formular.get("standortId")?.toString() || null;
|
||||
if (!hostId) return;
|
||||
|
||||
await prisma.host.update({ where: { id: hostId }, data: { kundeId, standortId } });
|
||||
await protokolliere("host.zugewiesen", "Host", hostId, { kundeId, standortId });
|
||||
|
||||
if (kundeId) {
|
||||
await prisma.alert.updateMany({
|
||||
where: { regel: "host-ohne-kunde", hostId, erledigtAm: null },
|
||||
data: { erledigtAm: new Date() },
|
||||
});
|
||||
}
|
||||
|
||||
revalidatePath(`/hosts/${hostId}`);
|
||||
revalidatePath("/hosts");
|
||||
revalidatePath("/hosts/nicht-zugeordnet");
|
||||
revalidatePath("/");
|
||||
}
|
||||
Reference in New Issue
Block a user