mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-26 23:46:59 -05:00
Refactor log_request_metadata function
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user