Commit 623e07e4 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix notification preferences 500 error — match actual DB schema

The component was querying a non-existent 'channels' JSON column.
The table uses separate boolean columns: channel_email, channel_sms, channel_in_app.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 6bb5fe27
...@@ -30,12 +30,20 @@ public function mount(): void ...@@ -30,12 +30,20 @@ public function mount(): void
$existing = DB::table('notification_preferences') $existing = DB::table('notification_preferences')
->where('user_id', $userId) ->where('user_id', $userId)
->pluck('channels', 'event_type') ->get()
->toArray(); ->keyBy('event_type');
foreach ($this->eventTypes as $type => $label) { foreach ($this->eventTypes as $type => $label) {
$channels = isset($existing[$type]) ? json_decode($existing[$type], true) : ['email' => true, 'sms' => true, 'in_app' => true]; if (isset($existing[$type])) {
$this->preferences[$type] = $channels; $row = $existing[$type];
$this->preferences[$type] = [
'email' => (bool) $row->channel_email,
'sms' => (bool) $row->channel_sms,
'in_app' => (bool) $row->channel_in_app,
];
} else {
$this->preferences[$type] = ['email' => true, 'sms' => true, 'in_app' => true];
}
} }
} }
...@@ -47,7 +55,12 @@ public function save(): void ...@@ -47,7 +55,12 @@ public function save(): void
DB::table('notification_preferences') DB::table('notification_preferences')
->updateOrInsert( ->updateOrInsert(
['user_id' => $userId, 'event_type' => $eventType], ['user_id' => $userId, 'event_type' => $eventType],
['channels' => json_encode($channels), 'updated_at' => now()] [
'channel_email' => $channels['email'] ?? true,
'channel_sms' => $channels['sms'] ?? true,
'channel_in_app' => true,
'updated_at' => now(),
]
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment