barsa 2b183272cf Implement Notifications Feature and Enhance BFF Modules
- Introduced a new Notification model in the Prisma schema to manage in-app notifications for users.
- Integrated the NotificationsModule into the BFF application, allowing for the handling of notifications related to user actions and events.
- Updated the CatalogCdcSubscriber to create notifications for account eligibility and verification status changes, improving user engagement.
- Enhanced the CheckoutRegistrationService to create opportunities for SIM orders, integrating with the new notifications system.
- Refactored various modules to include the NotificationsModule, ensuring seamless interaction and notification handling across the application.
- Updated the frontend to display notification alerts in the AppShell header, enhancing user experience and accessibility.
2025-12-23 11:36:44 +09:00

62 lines
1.7 KiB
TypeScript

/**
* 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<NotificationListResponse> {
const query: Record<string, string> = {};
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<NotificationListResponse>(BASE_PATH, {
params: { query },
});
return getDataOrThrow(response);
},
/**
* Get unread notification count
*/
async getUnreadCount(): Promise<number> {
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<void> {
await apiClient.POST<{ success: boolean }>(`${BASE_PATH}/${notificationId}/read`);
},
/**
* Mark all notifications as read
*/
async markAllAsRead(): Promise<void> {
await apiClient.POST<{ success: boolean }>(`${BASE_PATH}/read-all`);
},
/**
* Dismiss a notification
*/
async dismiss(notificationId: string): Promise<void> {
await apiClient.POST<{ success: boolean }>(`${BASE_PATH}/${notificationId}/dismiss`);
},
};