Projektordner in der Nextcloud anlegen und je nach Status verschieben (P10)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
Claude
2026-10-19 19:07:03 +00:00
parent 6615acf936
commit a3bb310cea
9 changed files with 256 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ import { type Client, type Pool, transaktion } from "./db.js";
import { mitNeuplanung, pruefeVerknuepfung, terminplan } from "./terminplan.js";
import { uebersicht } from "./uebersicht.js";
import { aufgabenKalender, baustellenKalender } from "./kalender.js";
import { type Nextcloud, ordnerAbgleichen } from "./nextcloud.js";
import { TABELLEN } from "./tabellen.js";
import { EinstellungenSchema, type Einstellungen } from "./einstellungen.js";
import { liquiditaet } from "../domain/liquiditaet.js";
@@ -19,6 +20,8 @@ import { VERSION } from "./version.js";
export interface Optionen {
pool: Pool;
/** P10: Projektordner in der Nextcloud; ohne Zugang wird nichts angelegt */
nextcloud?: Nextcloud;
webOrdner?: string;
logger?: boolean;
}
@@ -56,6 +59,28 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
return { ok: true, version: VERSION };
});
// P10: Ordner nach dem Speichern abgleichen. Ein Fehler in der Nextcloud macht die Änderung nicht
// rückgängig; der Hinweis kommt mit zurück, und der Abgleich lässt sich wiederholen.
async function mitOrdner(p: Record<string, any>, wer: string): Promise<Record<string, unknown>> {
if (!o.nextcloud) return p;
try {
const pfad = await ordnerAbgleichen(o.nextcloud, p as { nummer: string; bezeichnung: string; status: string }, p.nextcloud_link ?? null);
if (pfad === p.nextcloud_link) return p;
return await transaktion(pool, wer, async (c) => (await c.query("update projekt set nextcloud_link = $2 where id = $1 returning *", [p.id, pfad])).rows[0]);
} catch (err) {
app.log.warn(err);
return { ...p, ordner_fehler: `Projektordner in der Nextcloud: ${(err as Error).message}` };
}
}
app.post("/api/projekte/:id/ordner", async (req, reply) => {
const { id } = IdParam.parse(req.params);
const p = (await pool.query("select * from projekt where id = $1", [id])).rows[0];
if (!p) return reply.status(404).send({ fehler: "Nicht gefunden" });
if (!o.nextcloud) return reply.status(409).send({ fehler: "Für die Projektordner ist kein Nextcloud-Zugang eingerichtet." });
return mitOrdner(p, benutzer(req));
});
// Änderungen an Vorgängen und Verknüpfungen planen die Nachfolger in derselben Transaktion neu
const PLAN = new Set(["vorgang", "vorgang_vorgaenger"]);
async function geplant<T>(c: Client, tabelle: string, fn: () => Promise<T>, bewegt: string[] = []): Promise<T> {
@@ -89,6 +114,7 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
spalten.map((s) => daten[s]),
)).rows[0]);
});
if (t.name === "projekt") return reply.status(201).send(await mitOrdner(row, benutzer(req)));
return reply.status(201).send(row);
});
@@ -108,6 +134,7 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
[id, ...spalten.map((s) => daten[s])],
)).rows[0], t.name === "vorgang" && daten.start !== undefined ? [id] : []);
});
if (row && t.name === "projekt" && (daten.nummer || daten.bezeichnung || daten.status)) return mitOrdner(row, benutzer(req));
return row ?? reply.status(404).send({ fehler: "Nicht gefunden" });
});