diff --git a/lib/db/queries.ts b/lib/db/queries.ts index d37ea9621..067a7f7e1 100644 --- a/lib/db/queries.ts +++ b/lib/db/queries.ts @@ -3668,6 +3668,15 @@ export async function getAllSystemSettings() { } } +function normalizeSystemSettingUpdatedBy(updatedBy: string | null | undefined) { + const normalized = String(updatedBy || "").trim(); + return /^[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 + ) + ? normalized + : null; +} + export async function upsertSystemSetting({ key, value, @@ -3675,22 +3684,24 @@ export async function upsertSystemSetting({ }: { key: string; value: any; - updatedBy: string; + updatedBy: string | null | undefined; }) { + const normalizedUpdatedBy = normalizeSystemSettingUpdatedBy(updatedBy); + try { return await db .insert(systemSettings) .values({ key, value, - updatedBy, + updatedBy: normalizedUpdatedBy, updatedAt: new Date(), }) .onConflictDoUpdate({ target: systemSettings.key, set: { value, - updatedBy, + updatedBy: normalizedUpdatedBy, updatedAt: new Date(), }, })