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 =