fix: allow system setting writes from jobs

This commit is contained in:
Your Name 2026-06-01 18:39:30 +08:00
parent d82a47c035
commit 5d7e8ce773

View File

@ -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(),
},
})