From 48d101e13928ad33b5f9621775324c1c68406929 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Tue, 19 May 2026 16:31:57 +0200 Subject: [PATCH] =?UTF-8?q?KI-AGENT:=20Fehlerhafte=20Serienausf=C3=BChrung?= =?UTF-8?q?=20bei=20Belegen=20abfangen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/routes/resources/main.ts | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/backend/src/routes/resources/main.ts b/backend/src/routes/resources/main.ts index b7a5a7b..547cb64 100644 --- a/backend/src/routes/resources/main.ts +++ b/backend/src/routes/resources/main.ts @@ -230,6 +230,27 @@ function isDateLikeField(key: string) { return /(^|_|-)date($|_|-)/i.test(key) } +function normalizeCreatedDocumentPayload(payload: Record) { + const serialexecution = payload.serialexecution + if (serialexecution === undefined || serialexecution === null || serialexecution === "") return payload + + if (serialexecution instanceof Date) { + payload.serialexecution = null + return payload + } + + if (typeof serialexecution === "string") { + const normalized = serialexecution.trim() + const isUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(normalized) + if (!isUuid && !Number.isNaN(new Date(normalized).getTime())) { + payload.serialexecution = null + return payload + } + } + + return payload +} + function normalizeMemberPayload(payload: Record) { const infoData = payload.infoData && typeof payload.infoData === "object" ? payload.infoData : {} const normalized = { @@ -877,6 +898,10 @@ export default async function resourceRoutes(server: FastifyInstance) { } } + if (resource === "createddocuments") { + createData = normalizeCreatedDocumentPayload(createData) + } + if (config.numberRangeHolder && !body[config.numberRangeHolder]) { const numberRangeResource = resource === "members" ? "customers" : resource const result = await useNextNumberRangeNumber(server, req.user.tenant_id, numberRangeResource) @@ -1024,6 +1049,10 @@ export default async function resourceRoutes(server: FastifyInstance) { } } + if (resource === "createddocuments") { + data = normalizeCreatedDocumentPayload(data) + } + Object.keys(data).forEach((key) => { const value = data[key] const shouldNormalize =