Refactor log_request_metadata function

This commit is contained in:
gpt-engineer-app[bot]
2025-11-03 20:58:52 +00:00
parent 50e560f7cd
commit 19b1451f32
11 changed files with 992 additions and 63 deletions

View File

@@ -237,20 +237,36 @@ class NotificationService {
throw dbError;
}
// Create audit log entry
// DOCUMENTED EXCEPTION: profile_audit_log.changes column accepts JSONB
// We validate the preferences structure with Zod before this point
// Safe because the payload is constructed type-safely earlier in the function
await supabase.from('profile_audit_log').insert([{
user_id: userId,
changed_by: userId,
action: 'notification_preferences_updated',
changes: {
previous: previousPrefs || null,
updated: validated,
timestamp: new Date().toISOString()
}
}]);
// Create audit log entry using relational tables
const { data: auditLog, error: auditError } = await supabase
.from('profile_audit_log')
.insert([{
user_id: userId,
changed_by: userId,
action: 'notification_preferences_updated',
changes: {}, // Empty placeholder - actual changes stored in profile_change_fields table
}])
.select('id')
.single();
if (!auditError && auditLog) {
// Write changes to relational profile_change_fields table
const { writeProfileChangeFields } = await import('./auditHelpers');
await writeProfileChangeFields(auditLog.id, {
email_notifications: {
old_value: previousPrefs?.channel_preferences,
new_value: validated.channelPreferences,
},
workflow_preferences: {
old_value: previousPrefs?.workflow_preferences,
new_value: validated.workflowPreferences,
},
frequency_settings: {
old_value: previousPrefs?.frequency_settings,
new_value: validated.frequencySettings,
},
});
}
logger.info('Notification preferences updated', {
action: 'update_notification_preferences',