KI-AGENT: Datumswerte in Beleg-Relationen bereinigen
This commit is contained in:
@@ -230,11 +230,37 @@ function isDateLikeField(key: string) {
|
||||
return /(^|_|-)date($|_|-)/i.test(key)
|
||||
}
|
||||
|
||||
function isDateValue(value: any) {
|
||||
if (value instanceof Date) return !Number.isNaN(value.getTime())
|
||||
if (typeof value !== "string") return false
|
||||
const normalized = value.trim()
|
||||
if (/^\d+$/.test(normalized)) return false
|
||||
return !Number.isNaN(new Date(normalized).getTime())
|
||||
}
|
||||
|
||||
function normalizeCreatedDocumentPayload(payload: Record<string, any>) {
|
||||
const numberRelationFields = [
|
||||
"customer",
|
||||
"contact",
|
||||
"project",
|
||||
"createddocument",
|
||||
"letterhead",
|
||||
"plant",
|
||||
"contract",
|
||||
"outgoingsepamandate",
|
||||
]
|
||||
|
||||
for (const field of numberRelationFields) {
|
||||
const value = payload[field]
|
||||
if (value instanceof Date || (typeof value === "string" && isDateValue(value))) {
|
||||
payload[field] = null
|
||||
}
|
||||
}
|
||||
|
||||
const serialexecution = payload.serialexecution
|
||||
if (serialexecution === undefined || serialexecution === null || serialexecution === "") return payload
|
||||
|
||||
if (serialexecution instanceof Date) {
|
||||
if (isDateValue(serialexecution)) {
|
||||
payload.serialexecution = null
|
||||
return payload
|
||||
}
|
||||
@@ -242,7 +268,7 @@ function normalizeCreatedDocumentPayload(payload: Record<string, any>) {
|
||||
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())) {
|
||||
if (!isUuid && isDateValue(normalized)) {
|
||||
payload.serialexecution = null
|
||||
return payload
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user