import { prisma } from "@/lib/db"; /** Auswahl fuer „Public Key ausrollen auf …“ (#016): Hosts mit Bootstrap und Hostgruppen. */ export async function zielAuswahl() { const [hosts, gruppen] = await Promise.all([ prisma.host.findMany({ where: { archiviertAm: null }, select: { id: true, name: true, bootstrapAm: true }, orderBy: { name: "asc" }, }), prisma.hostgruppe.findMany({ select: { id: true, name: true, _count: { select: { mitglieder: true } } }, orderBy: { name: "asc" }, }), ]); return { hosts: hosts.map((h) => ({ id: h.id, name: h.name, bereit: h.bootstrapAm !== null })), gruppen: gruppen.map((g) => ({ id: g.id, name: g.name, mitglieder: g._count.mitglieder })), }; } export type ZielAuswahl = Awaited>; /** Was sshkv auf einem Host verwaltet (#016): Public Keys direkt und ueber Gruppen. */ export async function verwendungenAufHost(hostId: string) { const [oeffentlich, privat] = await Promise.all([ prisma.publicVerwendung.findMany({ where: { zustand: { not: "ENTFERNT" }, OR: [{ hostId }, { hostgruppe: { mitglieder: { some: { hostId } } } }], }, select: { id: true, zielbenutzer: true, optionen: true, zustand: true, hostgruppe: { select: { name: true } }, schluessel: { select: { id: true, name: true, typ: true, fingerprint: true } }, }, orderBy: [{ zielbenutzer: "asc" }, { angelegtAm: "asc" }], }), prisma.privateVerwendung.findMany({ where: { hostId, zustand: { not: "ENTFERNT" } }, select: { id: true, zielbenutzer: true, pfad: true, zustand: true, schluessel: { select: { id: true, name: true, typ: true, fingerprint: true } }, }, orderBy: [{ zielbenutzer: "asc" }, { pfad: "asc" }], }), ]); return { oeffentlich, privat }; }