Terminplan als Gantt: Verknüpfungen mit mehreren Vorgängern, Neuplanung der Nachfolger, Vorgangsnummern
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:
@@ -4,7 +4,8 @@ import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
import { existsSync } from "node:fs";
|
||||
import { z, ZodError } from "zod";
|
||||
import { type Pool, transaktion } from "./db.js";
|
||||
import { type Client, type Pool, transaktion } from "./db.js";
|
||||
import { mitNeuplanung, pruefeVerknuepfung, terminplan } from "./terminplan.js";
|
||||
import { TABELLEN } from "./tabellen.js";
|
||||
import { EinstellungenSchema, type Einstellungen } from "./einstellungen.js";
|
||||
import { liquiditaet } from "../domain/liquiditaet.js";
|
||||
@@ -52,6 +53,14 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
return { ok: true, version: VERSION };
|
||||
});
|
||||
|
||||
// Ä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> {
|
||||
if (!PLAN.has(tabelle)) return fn();
|
||||
const e = await ladeEinstellungen();
|
||||
return (await mitNeuplanung(c, { tage: e.arbeitstage }, fn, bewegt)).ergebnis;
|
||||
}
|
||||
|
||||
for (const t of TABELLEN) {
|
||||
const felder = Object.keys(t.schema.shape);
|
||||
const teil = t.schema.partial();
|
||||
@@ -67,14 +76,16 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
app.post(`/api/${t.pfad}`, async (req, reply) => {
|
||||
const daten = t.schema.parse(req.body) as Record<string, unknown>;
|
||||
const spalten = felder.filter((f) => daten[f] !== undefined);
|
||||
const row = await transaktion(pool, benutzer(req), async (c) =>
|
||||
(await c.query(
|
||||
spalten.length
|
||||
? `insert into ${t.name} (${spalten.join(", ")}) values (${spalten.map((_, i) => `$${i + 1}`).join(", ")}) returning *`
|
||||
: `insert into ${t.name} default values returning *`,
|
||||
spalten.map((s) => daten[s]),
|
||||
)).rows[0],
|
||||
);
|
||||
const row = await transaktion(pool, benutzer(req), async (c) => {
|
||||
if (t.name === "vorgang_vorgaenger") await pruefeVerknuepfung(c, daten as { vorgang_id: string; vorgaenger_id: string });
|
||||
return geplant(c, t.name, async () =>
|
||||
(await c.query(
|
||||
spalten.length
|
||||
? `insert into ${t.name} (${spalten.join(", ")}) values (${spalten.map((_, i) => `$${i + 1}`).join(", ")}) returning *`
|
||||
: `insert into ${t.name} default values returning *`,
|
||||
spalten.map((s) => daten[s]),
|
||||
)).rows[0]);
|
||||
});
|
||||
return reply.status(201).send(row);
|
||||
});
|
||||
|
||||
@@ -83,18 +94,24 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
const daten = teil.parse(req.body) as Record<string, unknown>;
|
||||
const spalten = felder.filter((f) => daten[f] !== undefined);
|
||||
if (spalten.length === 0) return reply.status(400).send({ fehler: "Keine Änderung angegeben" });
|
||||
const row = await transaktion(pool, benutzer(req), async (c) =>
|
||||
(await c.query(
|
||||
`update ${t.name} set ${spalten.map((s, i) => `${s} = $${i + 2}`).join(", ")} where id = $1 returning *`,
|
||||
[id, ...spalten.map((s) => daten[s])],
|
||||
)).rows[0],
|
||||
);
|
||||
const row = await transaktion(pool, benutzer(req), async (c) => {
|
||||
if (t.name === "vorgang_vorgaenger" && (daten.vorgang_id || daten.vorgaenger_id)) {
|
||||
const alt = (await c.query("select vorgang_id, vorgaenger_id from vorgang_vorgaenger where id = $1", [id])).rows[0];
|
||||
if (alt) await pruefeVerknuepfung(c, { ...alt, ...daten } as { vorgang_id: string; vorgaenger_id: string }, id);
|
||||
}
|
||||
return geplant(c, t.name, async () =>
|
||||
(await c.query(
|
||||
`update ${t.name} set ${spalten.map((s, i) => `${s} = $${i + 2}`).join(", ")} where id = $1 returning *`,
|
||||
[id, ...spalten.map((s) => daten[s])],
|
||||
)).rows[0], t.name === "vorgang" && daten.start !== undefined ? [id] : []);
|
||||
});
|
||||
return row ?? reply.status(404).send({ fehler: "Nicht gefunden" });
|
||||
});
|
||||
|
||||
app.delete(`/api/${t.pfad}/:id`, async (req, reply) => {
|
||||
const { id } = IdParam.parse(req.params);
|
||||
const n = await transaktion(pool, benutzer(req), async (c) => (await c.query(`delete from ${t.name} where id = $1`, [id])).rowCount);
|
||||
const n = await transaktion(pool, benutzer(req), async (c) =>
|
||||
geplant(c, t.name, async () => (await c.query(`delete from ${t.name} where id = $1`, [id])).rowCount));
|
||||
return n ? reply.status(204).send() : reply.status(404).send({ fehler: "Nicht gefunden" });
|
||||
});
|
||||
}
|
||||
@@ -144,6 +161,11 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
return liquiditaet(daten, { ansicht: q.ansicht, start, anzahl: q.anzahl, startsaldo: e.startsaldo, ziele: e.zahlungsziele, ust: e.ust });
|
||||
});
|
||||
|
||||
app.get("/api/terminplan", async () => {
|
||||
const e = await ladeEinstellungen();
|
||||
return terminplan(pool, { tage: e.arbeitstage });
|
||||
});
|
||||
|
||||
// Übernahme aus dem Projektplaner V70 (JSON-Sicherung), nur in ein leeres Programm
|
||||
app.post("/api/import/v70", async (req, reply) => {
|
||||
let u;
|
||||
@@ -152,7 +174,9 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
} catch (err) {
|
||||
return reply.status(400).send({ fehler: (err as Error).message });
|
||||
}
|
||||
const anzahl = await transaktion(pool, benutzer(req), (c) => speichereUebernahme(c, u));
|
||||
const e = await ladeEinstellungen();
|
||||
// nach der Übernahme gelten die Verknüpfungen: Nachfolger rücken hinter ihre Vorgänger wie in V70
|
||||
const anzahl = await transaktion(pool, benutzer(req), async (c) => (await mitNeuplanung(c, { tage: e.arbeitstage }, () => speichereUebernahme(c, u))).ergebnis);
|
||||
return reply.status(201).send({ anzahl, hinweise: u.hinweise });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user