From 4da70935b78de71a023e0a4abb96dcd7e799a62d Mon Sep 17 00:00:00 2001 From: Andrei Date: Thu, 9 Oct 2025 13:35:39 +0000 Subject: [PATCH] fix: Update notification bell API to match existing backend format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed notification bell integration by: - Updated API client to match backend's wrapped response format - Changed notification types to match database enums - Adjusted notification interface to include all backend fields - Backend notifications API already exists, no changes needed Backend endpoint: GET /api/v1/notifications returns: { success: true, data: { notifications: [...] } } 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- maternal-web/lib/api/notifications.ts | 59 ++++++++++++++++++--------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/maternal-web/lib/api/notifications.ts b/maternal-web/lib/api/notifications.ts index 916b6d5..13c41dc 100644 --- a/maternal-web/lib/api/notifications.ts +++ b/maternal-web/lib/api/notifications.ts @@ -3,22 +3,27 @@ import { apiClient } from './client'; export interface Notification { id: string; userId: string; - type: 'feeding' | 'sleep' | 'diaper' | 'medication' | 'milestone' | 'family' | 'system' | 'reminder'; + childId?: string; + type: 'feeding_reminder' | 'sleep_reminder' | 'diaper_reminder' | 'medication_reminder' | 'milestone_alert' | 'growth_tracking' | 'appointment_reminder' | 'pattern_anomaly'; + status: 'pending' | 'sent' | 'failed' | 'read' | 'dismissed'; + priority: 'low' | 'medium' | 'high' | 'urgent'; title: string; message: string; - data?: Record; - isRead: boolean; - isDismissed: boolean; - createdAt: string; + metadata?: Record; + scheduledFor?: string; + sentAt?: string | null; readAt?: string | null; dismissedAt?: string | null; + deviceToken?: string; + errorMessage?: string; + createdAt: string; + updatedAt: string; } export interface GetNotificationsParams { limit?: number; - offset?: number; - isRead?: boolean; - type?: Notification['type']; + status?: Notification['status']; + includeRead?: boolean; } export interface GetNotificationsResponse { @@ -27,46 +32,60 @@ export interface GetNotificationsResponse { unreadCount: number; } +// Backend response is wrapped in { success, data } +interface BackendResponse { + success: boolean; + data: T; + message?: string; +} + export const notificationsApi = { /** * Get user notifications with optional filters */ async getNotifications(params?: GetNotificationsParams): Promise { - const { data } = await apiClient.get('/notifications', { params }); - return data; + const { data } = await apiClient.get>('/notifications', { params }); + + const notifications = data.data.notifications; + const unreadCount = notifications.filter(n => !n.readAt && !n.dismissedAt).length; + + return { + notifications, + total: notifications.length, + unreadCount, + }; }, /** * Mark a notification as read */ async markAsRead(notificationId: string): Promise { - const { data } = await apiClient.patch(`/notifications/${notificationId}/read`); - return data; + const { data } = await apiClient.patch>(`/notifications/${notificationId}/read`); + // Backend returns success message, not the notification, so we return empty object + return {} as Notification; }, /** * Mark all notifications as read */ async markAllAsRead(): Promise<{ count: number }> { - const { data } = await apiClient.patch<{ count: number }>('/notifications/mark-all-read'); - return data; + await apiClient.patch>('/notifications/mark-all-read'); + return { count: 0 }; // Backend doesn't return count }, /** * Dismiss a notification */ async dismiss(notificationId: string): Promise { - const { data } = await apiClient.patch(`/notifications/${notificationId}/dismiss`); - return data; + await apiClient.patch>(`/notifications/${notificationId}/dismiss`); + return {} as Notification; }, /** * Get unread notification count */ async getUnreadCount(): Promise { - const { data } = await apiClient.get('/notifications', { - params: { limit: 1, isRead: false }, - }); - return data.unreadCount; + const response = await this.getNotifications({ limit: 100, includeRead: false }); + return response.unreadCount; }, };