feat(F-098): completed feature

This commit is contained in:
chattie
2026-08-20 22:39:06 +02:00
parent f1bf8c90c3
commit 3f1d08382f
8 changed files with 152 additions and 41 deletions

View File

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