feat: user notification preferences UI and API endpoints

GET/PUT /api/user/notification-preferences with partial update support.
Toggle section in /account Admin tab (Email, SMS, Browser push).
3 new tests: defaults, full update, partial update.
Fix pre-existing timezone bug in exceptional hours tests (Truncate vs time.Date).
Update README, Technical Manual, and gap backlog (#15 struck out).
This commit is contained in:
2026-05-17 00:24:13 +01:00
parent 7fc58f58d9
commit b08df624a8
9 changed files with 462 additions and 62 deletions
+9 -14
View File
@@ -538,13 +538,10 @@ CREATE TABLE admin_notifications (
CREATE TABLE user_notification_preferences (
id SERIAL PRIMARY KEY,
user_id CHAR(12) REFERENCES users(id) ON DELETE CASCADE,
notification_type VARCHAR(50) NOT NULL,
email_enabled BOOLEAN DEFAULT true,
sms_enabled BOOLEAN DEFAULT true,
push_enabled BOOLEAN DEFAULT true,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(user_id, notification_type)
email_enabled BOOLEAN DEFAULT false,
sms_enabled BOOLEAN DEFAULT false,
browser_push_enabled BOOLEAN DEFAULT false,
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX idx_user_notification_preferences_user_id ON user_notification_preferences(user_id);
@@ -776,14 +773,12 @@ BEGIN
'notification_preferences', (
SELECT COALESCE(json_agg(
json_build_object(
'notification_type', unp.notification_type,
'email_enabled', unp.email_enabled,
'sms_enabled', unp.sms_enabled,
'push_enabled', unp.push_enabled,
'created_at', unp.created_at,
'updated_at', unp.updated_at
'email_enabled', unp.email_enabled,
'sms_enabled', unp.sms_enabled,
'browser_push_enabled', unp.browser_push_enabled,
'updated_at', unp.updated_at
)
ORDER BY unp.notification_type), '[]'::json)
), '[]'::json)
FROM user_notification_preferences unp
WHERE unp.user_id = target_user_id
),