feat(F-098): completed feature
This commit is contained in:
@@ -98,6 +98,13 @@ export async function registerStoreSettingsRoutes(
|
||||
const input = parseJson(updateSettingsSchema, request.body);
|
||||
const updates: string[] = [];
|
||||
const values: unknown[] = [];
|
||||
const identityUser = await deps.pool.query<{ id: string }>(
|
||||
`SELECT id FROM identity_users WHERE id = $1`,
|
||||
[user.id],
|
||||
);
|
||||
// Backoffice users are a separate table. Keep the audit FK valid when the
|
||||
// authenticated backoffice id has no corresponding identity_users row.
|
||||
const updatedBy = identityUser.rowCount ? user.id : null;
|
||||
let i = 1;
|
||||
for (const [field, dbKey] of Object.entries(SETTING_KEYS)) {
|
||||
const val = input[field as keyof typeof input];
|
||||
@@ -115,7 +122,7 @@ export async function registerStoreSettingsRoutes(
|
||||
await deps.pool.query(
|
||||
`INSERT INTO store_settings (key, value, updated_by) VALUES ($1, $2, $3)
|
||||
ON CONFLICT (key) DO UPDATE SET value = $2, updated_at = NOW(), updated_by = $3`,
|
||||
[dbKey, val, user.id],
|
||||
[dbKey, val, updatedBy],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user