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
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:
@@ -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<string, any>;
|
||||
isRead: boolean;
|
||||
isDismissed: boolean;
|
||||
createdAt: string;
|
||||
metadata?: Record<string, any>;
|
||||
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<T> {
|
||||
success: boolean;
|
||||
data: T;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export const notificationsApi = {
|
||||
/**
|
||||
* Get user notifications with optional filters
|
||||
*/
|
||||
async getNotifications(params?: GetNotificationsParams): Promise<GetNotificationsResponse> {
|
||||
const { data } = await apiClient.get<GetNotificationsResponse>('/notifications', { params });
|
||||
return data;
|
||||
const { data } = await apiClient.get<BackendResponse<{ notifications: Notification[] }>>('/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<Notification> {
|
||||
const { data } = await apiClient.patch<Notification>(`/notifications/${notificationId}/read`);
|
||||
return data;
|
||||
const { data } = await apiClient.patch<BackendResponse<any>>(`/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<BackendResponse<any>>('/notifications/mark-all-read');
|
||||
return { count: 0 }; // Backend doesn't return count
|
||||
},
|
||||
|
||||
/**
|
||||
* Dismiss a notification
|
||||
*/
|
||||
async dismiss(notificationId: string): Promise<Notification> {
|
||||
const { data } = await apiClient.patch<Notification>(`/notifications/${notificationId}/dismiss`);
|
||||
return data;
|
||||
await apiClient.patch<BackendResponse<any>>(`/notifications/${notificationId}/dismiss`);
|
||||
return {} as Notification;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get unread notification count
|
||||
*/
|
||||
async getUnreadCount(): Promise<number> {
|
||||
const { data } = await apiClient.get<GetNotificationsResponse>('/notifications', {
|
||||
params: { limit: 1, isRead: false },
|
||||
});
|
||||
return data.unreadCount;
|
||||
const response = await this.getNotifications({ limit: 100, includeRead: false });
|
||||
return response.unreadCount;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user