fix: allow system setting writes from jobs
This commit is contained in:
parent
d82a47c035
commit
5d7e8ce773
@ -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({
|
export async function upsertSystemSetting({
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
@ -3675,22 +3684,24 @@ export async function upsertSystemSetting({
|
|||||||
}: {
|
}: {
|
||||||
key: string;
|
key: string;
|
||||||
value: any;
|
value: any;
|
||||||
updatedBy: string;
|
updatedBy: string | null | undefined;
|
||||||
}) {
|
}) {
|
||||||
|
const normalizedUpdatedBy = normalizeSystemSettingUpdatedBy(updatedBy);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await db
|
return await db
|
||||||
.insert(systemSettings)
|
.insert(systemSettings)
|
||||||
.values({
|
.values({
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
updatedBy,
|
updatedBy: normalizedUpdatedBy,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.onConflictDoUpdate({
|
.onConflictDoUpdate({
|
||||||
target: systemSettings.key,
|
target: systemSettings.key,
|
||||||
set: {
|
set: {
|
||||||
value,
|
value,
|
||||||
updatedBy,
|
updatedBy: normalizedUpdatedBy,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user