KI-AGENT: Beleg-Relationswerte vor dem Speichern normalisieren
This commit is contained in:
@@ -936,7 +936,16 @@ export default async function resourceRoutes(server: FastifyInstance) {
|
||||
|
||||
const normalizeDate = (val: any) => { const d = new Date(val); return isNaN(d.getTime()) ? null : d; }
|
||||
Object.keys(createData).forEach((key) => {
|
||||
if (key.toLowerCase().includes("date") && key !== "deliveryDateType") createData[key] = normalizeDate(createData[key])
|
||||
const value = createData[key]
|
||||
const shouldNormalize =
|
||||
isDateLikeField(key) &&
|
||||
value !== null &&
|
||||
value !== undefined &&
|
||||
(typeof value === "string" || typeof value === "number" || value instanceof Date)
|
||||
|
||||
if (shouldNormalize) {
|
||||
createData[key] = normalizeDate(value)
|
||||
}
|
||||
})
|
||||
|
||||
const [created] = await server.db.insert(table).values(createData).returning()
|
||||
|
||||
@@ -303,6 +303,11 @@ watch(
|
||||
const loaded = ref(false)
|
||||
const normalizeEntityId = (value) => {
|
||||
if (value === null || typeof value === "undefined") return null
|
||||
if (value instanceof Date) return null
|
||||
if (typeof value === "string") {
|
||||
const normalized = value.trim()
|
||||
if (!/^\d+$/.test(normalized) && dayjs(normalized).isValid()) return null
|
||||
}
|
||||
return typeof value === "object" ? (value.id ?? null) : value
|
||||
}
|
||||
const normalizeCreatedDocumentRow = (row) => {
|
||||
@@ -1567,14 +1572,14 @@ const saveSerialInvoice = async () => {
|
||||
let createData = {
|
||||
type: itemInfo.value.type,
|
||||
state: 'Erstellt',
|
||||
customer: itemInfo.value.customer,
|
||||
contact: itemInfo.value.contact,
|
||||
contract: itemInfo.value.contract,
|
||||
customer: normalizeEntityId(itemInfo.value.customer),
|
||||
contact: normalizeEntityId(itemInfo.value.contact),
|
||||
contract: normalizeEntityId(itemInfo.value.contract),
|
||||
address: itemInfo.value.address,
|
||||
project: itemInfo.value.project,
|
||||
project: normalizeEntityId(itemInfo.value.project),
|
||||
paymentDays: itemInfo.value.paymentDays,
|
||||
payment_type: itemInfo.value.payment_type,
|
||||
outgoingsepamandate: itemInfo.value.outgoingsepamandate,
|
||||
outgoingsepamandate: normalizeEntityId(itemInfo.value.outgoingsepamandate),
|
||||
deliveryDateType: "Leistungszeitraum",
|
||||
createdBy: itemInfo.value.createdBy,
|
||||
created_by: itemInfo.value.created_by,
|
||||
@@ -1650,19 +1655,19 @@ const saveDocument = async (state, resetup = false) => {
|
||||
type: itemInfo.value.type,
|
||||
taxType: ['invoices', 'cancellationInvoices', 'advanceInvoices', 'confirmationOrders', ...quoteLikeDocumentTypes].includes(itemInfo.value.type) ? normalizeTaxTypeValue(itemInfo.value.taxType) : null,
|
||||
state: itemInfo.value.state || "Entwurf",
|
||||
customer: itemInfo.value.customer,
|
||||
contact: itemInfo.value.contact,
|
||||
contract: itemInfo.value.contract,
|
||||
customer: normalizeEntityId(itemInfo.value.customer),
|
||||
contact: normalizeEntityId(itemInfo.value.contact),
|
||||
contract: normalizeEntityId(itemInfo.value.contract),
|
||||
address: itemInfo.value.address,
|
||||
project: itemInfo.value.project,
|
||||
plant: itemInfo.value.plant,
|
||||
project: normalizeEntityId(itemInfo.value.project),
|
||||
plant: normalizeEntityId(itemInfo.value.plant),
|
||||
documentNumber: itemInfo.value.documentNumber,
|
||||
documentDate: itemInfo.value.documentDate,
|
||||
deliveryDate: itemInfo.value.deliveryDate,
|
||||
deliveryDateEnd: itemInfo.value.deliveryDateEnd,
|
||||
paymentDays: itemInfo.value.paymentDays,
|
||||
payment_type: itemInfo.value.payment_type,
|
||||
outgoingsepamandate: itemInfo.value.outgoingsepamandate,
|
||||
outgoingsepamandate: normalizeEntityId(itemInfo.value.outgoingsepamandate),
|
||||
deliveryDateType: itemInfo.value.deliveryDateType,
|
||||
info: {},
|
||||
createdBy: itemInfo.value.createdBy,
|
||||
@@ -1673,9 +1678,9 @@ const saveDocument = async (state, resetup = false) => {
|
||||
endText: itemInfo.value.endText,
|
||||
rows: itemInfo.value.rows,
|
||||
contactPerson: itemInfo.value.contactPerson,
|
||||
createddocument: itemInfo.value.createddocument,
|
||||
createddocument: normalizeEntityId(itemInfo.value.createddocument),
|
||||
agriculture: itemInfo.value.agriculture,
|
||||
letterhead: itemInfo.value.letterhead,
|
||||
letterhead: normalizeEntityId(itemInfo.value.letterhead),
|
||||
usedAdvanceInvoices: itemInfo.value.usedAdvanceInvoices,
|
||||
availableInPortal: itemInfo.value.availableInPortal,
|
||||
customSurchargePercentage: itemInfo.value.customSurchargePercentage,
|
||||
|
||||
Reference in New Issue
Block a user