/** * Notifications API * * Endpoints for managing user notifications */ import { get, post, patch, del } from './client'; import type { NotificationResponse, NotificationListResponse, SuccessResponse, } from '@/types/api'; // TODO: These types should be moved to @/types/api.ts export interface CreateNotificationRequest { userId?: string; type: string; title: string; message: string; } export interface UpdateNotificationPreferencesRequest { emailNotifications?: boolean; pushNotifications?: boolean; smsNotifications?: boolean; notificationTypes?: string[]; } export interface NotificationPreferencesResponse { userId: string; emailNotifications: boolean; pushNotifications: boolean; smsNotifications: boolean; notificationTypes: string[]; updatedAt: string; } /** * List user notifications with pagination * GET /api/v1/notifications?page=1&limit=20&isRead=false&type=BOOKING_CONFIRMED */ export async function listNotifications(params?: { page?: number; limit?: number; isRead?: boolean; type?: string; }): Promise { const queryParams = new URLSearchParams(); if (params?.page) queryParams.append('page', params.page.toString()); if (params?.limit) queryParams.append('limit', params.limit.toString()); if (params?.isRead !== undefined) queryParams.append('isRead', params.isRead.toString()); if (params?.type) queryParams.append('type', params.type); const queryString = queryParams.toString(); return get( `/api/v1/notifications${queryString ? `?${queryString}` : ''}` ); } /** * Get notification by ID * GET /api/v1/notifications/:id */ export async function getNotification(id: string): Promise { return get(`/api/v1/notifications/${id}`); } /** * Create notification (admin only) * POST /api/v1/notifications * Requires: ADMIN role */ export async function createNotification( data: CreateNotificationRequest ): Promise { return post('/api/v1/notifications', data); } /** * Mark notification as read * PATCH /api/v1/notifications/:id/read */ export async function markNotificationAsRead(id: string): Promise { return patch(`/api/v1/notifications/${id}/read`, {}); } /** * Mark all notifications as read * PATCH /api/v1/notifications/read-all */ export async function markAllNotificationsAsRead(): Promise { return patch('/api/v1/notifications/read-all', {}); } /** * Delete notification * DELETE /api/v1/notifications/:id */ export async function deleteNotification(id: string): Promise { return del(`/api/v1/notifications/${id}`); } /** * Get notification preferences * GET /api/v1/notifications/preferences */ export async function getNotificationPreferences(): Promise { return get('/api/v1/notifications/preferences'); } /** * Update notification preferences * PATCH /api/v1/notifications/preferences */ export async function updateNotificationPreferences( data: UpdateNotificationPreferencesRequest ): Promise { return patch('/api/v1/notifications/preferences', data); }