/** * Notification Service * * Handles API calls for in-app notifications. */ import { apiClient, getDataOrThrow } from "@/lib/api"; import type { NotificationListResponse } from "@customer-portal/domain/notifications"; const BASE_PATH = "/api/notifications"; export const notificationService = { /** * Get notifications for the current user */ async getNotifications(params?: { limit?: number; offset?: number; includeRead?: boolean; }): Promise { const query: Record = {}; if (params?.limit) query.limit = String(params.limit); if (params?.offset) query.offset = String(params.offset); if (params?.includeRead !== undefined) query.includeRead = String(params.includeRead); const response = await apiClient.GET(BASE_PATH, { params: { query }, }); return getDataOrThrow(response); }, /** * Get unread notification count */ async getUnreadCount(): Promise { const response = await apiClient.GET<{ count: number }>(`${BASE_PATH}/unread-count`); const data = getDataOrThrow(response); return data.count; }, /** * Mark a notification as read */ async markAsRead(notificationId: string): Promise { await apiClient.POST<{ success: boolean }>(`${BASE_PATH}/${notificationId}/read`); }, /** * Mark all notifications as read */ async markAllAsRead(): Promise { await apiClient.POST<{ success: boolean }>(`${BASE_PATH}/read-all`); }, /** * Dismiss a notification */ async dismiss(notificationId: string): Promise { await apiClient.POST<{ success: boolean }>(`${BASE_PATH}/${notificationId}/dismiss`); }, };