import { datenbank, schema } from '../db'; import { jetzt } from '../zeit'; import { standAus, type ModulId, type ModulStand } from '../module/module'; /** Sämtlicher Zugriff auf die Tabelle `modul_einstellung` läuft über dieses Modul. */ /** Der aktuelle Stand aller Module. Ohne gespeicherte Zeile ist ein Modul an. */ export function modulStand(): ModulStand { const zeilen = datenbank() .select({ modul: schema.modulEinstellung.modul, aktiv: schema.modulEinstellung.aktiv }) .from(schema.modulEinstellung) .all(); return standAus(zeilen); } /** Wer wann zuletzt umgeschaltet hat – für die Anzeige in der Verwaltung. */ export function modulAenderungen() { return datenbank().select().from(schema.modulEinstellung).all(); } export function modulSetzen(modul: ModulId, aktiv: boolean, benutzerId: string): void { const werte = { aktiv: aktiv ? 1 : 0, geaendertVon: benutzerId, geaendertAm: jetzt() }; datenbank() .insert(schema.modulEinstellung) .values({ modul, ...werte }) .onConflictDoUpdate({ target: schema.modulEinstellung.modul, set: werte }) .run(); }