Personal: Stammdaten, Arbeitszeitmodell, Abwesenheiten, Urlaubskonto (0.8.0)
Stufe 2, Schritt 2 (M1, M8, M4, M10-Konto). Modelle mit Gültig-ab, Abwesenheiten ganztags, halbtags oder stundengenau, Verfügbarkeit je Tag als Grundlage für T15/T16. Lohnkosten je Stunde nur für den Inhaber (nurInhaber in TABELLEN). 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:
@@ -21,6 +21,7 @@ import { benutzerFuerSicherung, pruefeStand, speichereStand } from "./stand.js";
|
||||
import { VERSION } from "./version.js";
|
||||
import { type Anmeldeart, registriereAnmeldung, werName } from "./anmeldung.js";
|
||||
import { istEingeteilt, registriereIch } from "./ich.js";
|
||||
import { registrierePersonal } from "./personal.js";
|
||||
|
||||
export interface Optionen {
|
||||
pool: Pool;
|
||||
@@ -62,6 +63,7 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
registriereAnmeldung(app, pool, o.anmeldung ?? "passwort", o.einrichtungsCode);
|
||||
|
||||
registriereIch(app, pool, ladeEinstellungen);
|
||||
registrierePersonal(app, pool, ladeEinstellungen);
|
||||
|
||||
app.get("/api/status", async () => {
|
||||
await pool.query("select 1");
|
||||
@@ -158,20 +160,32 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
const projektDerZahlung = async (c: Client, tabelle: string, id: string) =>
|
||||
tabelle === "zahlung" ? (await c.query("select projekt_id from zahlung where id = $1", [id])).rows[0]?.projekt_id as string | undefined : undefined;
|
||||
|
||||
// U2: Felder wie der Stundenlohn gehen nur an den Inhaber; Zahlen-Arrays (Arbeitszeitmodell) als Zahlen
|
||||
const fuer = (req: FastifyRequest, t: (typeof TABELLEN)[number]) => (z: Record<string, unknown> | undefined) => {
|
||||
if (!z) return z;
|
||||
const aus: Record<string, unknown> = { ...z };
|
||||
if (req.wer?.rolle !== "inhaber") for (const f of t.nurInhaber ?? []) delete aus[f];
|
||||
for (const [k, v] of Object.entries(aus)) if (Array.isArray(v)) aus[k] = v.map((x) => (typeof x === "string" && /^-?\d+(\.\d+)?$/.test(x) ? Number(x) : x));
|
||||
return aus;
|
||||
};
|
||||
const verboten = (req: FastifyRequest, t: (typeof TABELLEN)[number], daten: Record<string, unknown>) =>
|
||||
req.wer?.rolle !== "inhaber" && (t.nurInhaber ?? []).some((f) => daten[f] !== undefined);
|
||||
|
||||
for (const t of TABELLEN) {
|
||||
const felder = Object.keys(t.schema.shape);
|
||||
const teil = t.schema.partial();
|
||||
|
||||
app.get(`/api/${t.pfad}`, async () => (await pool.query(`select * from ${t.name} order by ${t.sortierung}`)).rows);
|
||||
app.get(`/api/${t.pfad}`, async (req) => (await pool.query(`select * from ${t.name} order by ${t.sortierung}`)).rows.map(fuer(req, t)));
|
||||
|
||||
app.get(`/api/${t.pfad}/:id`, async (req, reply) => {
|
||||
const { id } = IdParam.parse(req.params);
|
||||
const r = await pool.query(`select * from ${t.name} where id = $1`, [id]);
|
||||
return r.rows[0] ?? reply.status(404).send({ fehler: "Nicht gefunden" });
|
||||
return fuer(req, t)(r.rows[0]) ?? reply.status(404).send({ fehler: "Nicht gefunden" });
|
||||
});
|
||||
|
||||
app.post(`/api/${t.pfad}`, async (req, reply) => {
|
||||
const daten = t.schema.parse(req.body) as Record<string, unknown>;
|
||||
if (verboten(req, t, daten)) return reply.status(403).send({ fehler: "Dafür fehlt dir die Berechtigung." });
|
||||
const spalten = felder.filter((f) => daten[f] !== undefined);
|
||||
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 });
|
||||
@@ -184,12 +198,13 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
)).rows[0], [], t.name === "zahlung" ? daten.projekt_id as string : undefined);
|
||||
});
|
||||
if (t.name === "projekt") return reply.status(201).send(await mitOrdner(row, benutzer(req)));
|
||||
return reply.status(201).send(row);
|
||||
return reply.status(201).send(fuer(req, t)(row));
|
||||
});
|
||||
|
||||
app.patch(`/api/${t.pfad}/:id`, async (req, reply) => {
|
||||
const { id } = IdParam.parse(req.params);
|
||||
const daten = teil.parse(req.body) as Record<string, unknown>;
|
||||
if (verboten(req, t, daten)) return reply.status(403).send({ fehler: "Dafür fehlt dir die Berechtigung." });
|
||||
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) => {
|
||||
@@ -205,7 +220,7 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
)).rows[0], t.name === "vorgang" && daten.start !== undefined ? [id] : [], zahlungVon);
|
||||
});
|
||||
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" });
|
||||
return fuer(req, t)(row) ?? reply.status(404).send({ fehler: "Nicht gefunden" });
|
||||
});
|
||||
|
||||
app.delete(`/api/${t.pfad}/:id`, async (req, reply) => {
|
||||
|
||||
Reference in New Issue
Block a user