fix: Update notification bell API to match existing backend format
Some checks failed
ParentFlow CI/CD Pipeline / Backend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Frontend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Security Scanning (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-app/maternal-app-backend dockerfile:Dockerfile.production name:backend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-web dockerfile:Dockerfile.production name:frontend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Development (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled

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 <noreply@anthropic.com>
This commit is contained in:
Andrei
2025-10-09 13:35:39 +00:00
parent 090fe7f63b
commit 4da70935b7

View File

@@ -3,22 +3,27 @@ import { apiClient } from './client';
export interface Notification { export interface Notification {
id: string; id: string;
userId: 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; title: string;
message: string; message: string;
data?: Record<string, any>; metadata?: Record<string, any>;
isRead: boolean; scheduledFor?: string;
isDismissed: boolean; sentAt?: string | null;
createdAt: string;
readAt?: string | null; readAt?: string | null;
dismissedAt?: string | null; dismissedAt?: string | null;
deviceToken?: string;
errorMessage?: string;
createdAt: string;
updatedAt: string;
} }
export interface GetNotificationsParams { export interface GetNotificationsParams {
limit?: number; limit?: number;
offset?: number; status?: Notification['status'];
isRead?: boolean; includeRead?: boolean;
type?: Notification['type'];
} }
export interface GetNotificationsResponse { export interface GetNotificationsResponse {
@@ -27,46 +32,60 @@ export interface GetNotificationsResponse {
unreadCount: number; unreadCount: number;
} }
// Backend response is wrapped in { success, data }
interface BackendResponse<T> {
success: boolean;
data: T;
message?: string;
}
export const notificationsApi = { export const notificationsApi = {
/** /**
* Get user notifications with optional filters * Get user notifications with optional filters
*/ */
async getNotifications(params?: GetNotificationsParams): Promise<GetNotificationsResponse> { async getNotifications(params?: GetNotificationsParams): Promise<GetNotificationsResponse> {
const { data } = await apiClient.get<GetNotificationsResponse>('/notifications', { params }); const { data } = await apiClient.get<BackendResponse<{ notifications: Notification[] }>>('/notifications', { params });
return data;
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 * Mark a notification as read
*/ */
async markAsRead(notificationId: string): Promise<Notification> { async markAsRead(notificationId: string): Promise<Notification> {
const { data } = await apiClient.patch<Notification>(`/notifications/${notificationId}/read`); const { data } = await apiClient.patch<BackendResponse<any>>(`/notifications/${notificationId}/read`);
return data; // Backend returns success message, not the notification, so we return empty object
return {} as Notification;
}, },
/** /**
* Mark all notifications as read * Mark all notifications as read
*/ */
async markAllAsRead(): Promise<{ count: number }> { async markAllAsRead(): Promise<{ count: number }> {
const { data } = await apiClient.patch<{ count: number }>('/notifications/mark-all-read'); await apiClient.patch<BackendResponse<any>>('/notifications/mark-all-read');
return data; return { count: 0 }; // Backend doesn't return count
}, },
/** /**
* Dismiss a notification * Dismiss a notification
*/ */
async dismiss(notificationId: string): Promise<Notification> { async dismiss(notificationId: string): Promise<Notification> {
const { data } = await apiClient.patch<Notification>(`/notifications/${notificationId}/dismiss`); await apiClient.patch<BackendResponse<any>>(`/notifications/${notificationId}/dismiss`);
return data; return {} as Notification;
}, },
/** /**
* Get unread notification count * Get unread notification count
*/ */
async getUnreadCount(): Promise<number> { async getUnreadCount(): Promise<number> {
const { data } = await apiClient.get<GetNotificationsResponse>('/notifications', { const response = await this.getNotifications({ limit: 100, includeRead: false });
params: { limit: 1, isRead: false }, return response.unreadCount;
});
return data.unreadCount;
}, },
}; };