KI-AGENT: Fehlerhafte Serienausführung bei Belegen abfangen

This commit is contained in:
2026-05-19 16:31:57 +02:00
parent 167e9a40c3
commit 48d101e139

View File

@@ -230,6 +230,27 @@ function isDateLikeField(key: string) {
return /(^|_|-)date($|_|-)/i.test(key) return /(^|_|-)date($|_|-)/i.test(key)
} }
function normalizeCreatedDocumentPayload(payload: Record<string, any>) {
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<string, any>) { function normalizeMemberPayload(payload: Record<string, any>) {
const infoData = payload.infoData && typeof payload.infoData === "object" ? payload.infoData : {} const infoData = payload.infoData && typeof payload.infoData === "object" ? payload.infoData : {}
const normalized = { 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]) { if (config.numberRangeHolder && !body[config.numberRangeHolder]) {
const numberRangeResource = resource === "members" ? "customers" : resource const numberRangeResource = resource === "members" ? "customers" : resource
const result = await useNextNumberRangeNumber(server, req.user.tenant_id, numberRangeResource) 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) => { Object.keys(data).forEach((key) => {
const value = data[key] const value = data[key]
const shouldNormalize = const shouldNormalize =