// frontend/src/api/services/notification.service.ts /** * Notification Service * Handles notification operations */ import { apiClient } from '../client'; import type { NotificationCreate, NotificationResponse, NotificationTemplate, NotificationHistory, NotificationStats, BulkNotificationRequest, BulkNotificationStatus, PaginatedResponse, BaseQueryParams, } from '../types'; export class NotificationService { /** * Send Notification */ async sendNotification( tenantId: string, notification: NotificationCreate ): Promise { return apiClient.post(`/tenants/${tenantId}/notifications`, notification); } /** * Send Bulk Notifications */ async sendBulkNotifications( tenantId: string, request: BulkNotificationRequest ): Promise { return apiClient.post(`/tenants/${tenantId}/notifications/bulk`, request); } /** * Get Notifications */ async getNotifications( tenantId: string, params?: BaseQueryParams & { channel?: string; status?: string; recipient_email?: string; start_date?: string; end_date?: string; } ): Promise> { return apiClient.get(`/tenants/${tenantId}/notifications`, { params }); } /** * Get Notification by ID */ async getNotification(tenantId: string, notificationId: string): Promise { return apiClient.get(`/tenants/${tenantId}/notifications/${notificationId}`); } /** * Get Notification History */ async getNotificationHistory( tenantId: string, notificationId: string ): Promise { return apiClient.get(`/tenants/${tenantId}/notifications/${notificationId}/history`); } /** * Cancel Scheduled Notification */ async cancelNotification( tenantId: string, notificationId: string ): Promise<{ message: string }> { return apiClient.post(`/tenants/${tenantId}/notifications/${notificationId}/cancel`); } /** * Get Bulk Notification Status */ async getBulkNotificationStatus( tenantId: string, batchId: string ): Promise { return apiClient.get(`/tenants/${tenantId}/notifications/bulk/${batchId}/status`); } /** * Get Notification Templates */ async getTemplates( tenantId: string, params?: BaseQueryParams & { channel?: string; is_active?: boolean; } ): Promise> { return apiClient.get(`/tenants/${tenantId}/notifications/templates`, { params }); } /** * Create Notification Template */ async createTemplate( tenantId: string, template: Omit ): Promise { return apiClient.post(`/tenants/${tenantId}/notifications/templates`, template); } /** * Update Notification Template */ async updateTemplate( tenantId: string, templateId: string, template: Partial ): Promise { return apiClient.put(`/tenants/${tenantId}/notifications/templates/${templateId}`, template); } /** * Delete Notification Template */ async deleteTemplate(tenantId: string, templateId: string): Promise<{ message: string }> { return apiClient.delete(`/tenants/${tenantId}/notifications/templates/${templateId}`); } /** * Get Notification Statistics */ async getNotificationStats( tenantId: string, params?: { start_date?: string; end_date?: string; channel?: string; } ): Promise { return apiClient.get(`/tenants/${tenantId}/notifications/stats`, { params }); } /** * Test Notification Configuration */ async testNotificationConfig( tenantId: string, config: { channel: string; recipient: string; test_message: string; } ): Promise<{ success: boolean; message: string }> { return apiClient.post(`/tenants/${tenantId}/notifications/test`, config); } /** * Get User Notification Preferences */ async getUserPreferences(tenantId: string, userId: string): Promise> { return apiClient.get(`/tenants/${tenantId}/notifications/preferences/${userId}`); } /** * Update User Notification Preferences */ async updateUserPreferences( tenantId: string, userId: string, preferences: Record ): Promise<{ message: string }> { return apiClient.put( `/tenants/${tenantId}/notifications/preferences/${userId}`, preferences ); } } export const notificationService = new NotificationService();