All files / src/services/api notificationsApi.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                                                1x       6x   6x 4x               1x     7x 4x               1x     5x     2x    
/**
 * Notifications API Service
 * Story 1.17 & 1.26: Type-safe API client wrappers for notification endpoints
 *
 * Endpoints:
 * - GET /api/v1/notifications?status=unread&limit=10
 * - PUT /api/v1/notifications/read
 * - DELETE /api/v1/notifications/{id}
 */
 
import apiClient from './apiClient';
import {
  NotificationsResponse,
  MarkAsReadRequest,
  MarkAsReadResponse,
  DeleteNotificationResponse,
} from '@/types/notification';
 
/**
 * Fetch notifications with optional filters
 * @param status - Filter by status ('unread' or 'all')
 * @param limit - Maximum number of notifications to fetch
 * @returns Notifications response with unread count
 */
export const getNotifications = async (
  status: 'unread' | 'all' = 'unread',
  limit: number = 10
): Promise<NotificationsResponse> => {
  const params = { status, limit };
 
  const response = await apiClient.get<NotificationsResponse>('/notifications', { params });
  return response.data;
};
 
/**
 * Mark notification(s) as read
 * @param request - Notification IDs or markAll flag
 * @returns Mark as read response with count
 */
export const markNotificationsAsRead = async (
  request: MarkAsReadRequest
): Promise<MarkAsReadResponse> => {
  const response = await apiClient.put<MarkAsReadResponse>('/notifications/read', request);
  return response.data;
};
 
/**
 * Delete a notification
 * @param notificationId - Notification ID to delete
 * @returns Delete confirmation
 */
export const deleteNotification = async (
  notificationId: string
): Promise<DeleteNotificationResponse> => {
  const response = await apiClient.delete<DeleteNotificationResponse>(
    `/notifications/${notificationId}`
  );
  return response.data;
};