186 lines
4.7 KiB
TypeScript
186 lines
4.7 KiB
TypeScript
// 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<NotificationResponse> {
|
|
return apiClient.post(`/tenants/${tenantId}/notifications`, notification);
|
|
}
|
|
|
|
/**
|
|
* Send Bulk Notifications
|
|
*/
|
|
async sendBulkNotifications(
|
|
tenantId: string,
|
|
request: BulkNotificationRequest
|
|
): Promise<BulkNotificationStatus> {
|
|
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<PaginatedResponse<NotificationResponse>> {
|
|
return apiClient.get(`/tenants/${tenantId}/notifications`, { params });
|
|
}
|
|
|
|
/**
|
|
* Get Notification by ID
|
|
*/
|
|
async getNotification(tenantId: string, notificationId: string): Promise<NotificationResponse> {
|
|
return apiClient.get(`/tenants/${tenantId}/notifications/${notificationId}`);
|
|
}
|
|
|
|
/**
|
|
* Get Notification History
|
|
*/
|
|
async getNotificationHistory(
|
|
tenantId: string,
|
|
notificationId: string
|
|
): Promise<NotificationHistory[]> {
|
|
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<BulkNotificationStatus> {
|
|
return apiClient.get(`/tenants/${tenantId}/notifications/bulk/${batchId}/status`);
|
|
}
|
|
|
|
/**
|
|
* Get Notification Templates
|
|
*/
|
|
async getTemplates(
|
|
tenantId: string,
|
|
params?: BaseQueryParams & {
|
|
channel?: string;
|
|
is_active?: boolean;
|
|
}
|
|
): Promise<PaginatedResponse<NotificationTemplate>> {
|
|
return apiClient.get(`/tenants/${tenantId}/notifications/templates`, { params });
|
|
}
|
|
|
|
/**
|
|
* Create Notification Template
|
|
*/
|
|
async createTemplate(
|
|
tenantId: string,
|
|
template: Omit<NotificationTemplate, 'id' | 'tenant_id' | 'created_at' | 'updated_at'>
|
|
): Promise<NotificationTemplate> {
|
|
return apiClient.post(`/tenants/${tenantId}/notifications/templates`, template);
|
|
}
|
|
|
|
/**
|
|
* Update Notification Template
|
|
*/
|
|
async updateTemplate(
|
|
tenantId: string,
|
|
templateId: string,
|
|
template: Partial<NotificationTemplate>
|
|
): Promise<NotificationTemplate> {
|
|
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<NotificationStats> {
|
|
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<Record<string, boolean>> {
|
|
return apiClient.get(`/tenants/${tenantId}/notifications/preferences/${userId}`);
|
|
}
|
|
|
|
/**
|
|
* Update User Notification Preferences
|
|
*/
|
|
async updateUserPreferences(
|
|
tenantId: string,
|
|
userId: string,
|
|
preferences: Record<string, boolean>
|
|
): Promise<{ message: string }> {
|
|
return apiClient.put(
|
|
`/tenants/${tenantId}/notifications/preferences/${userId}`,
|
|
preferences
|
|
);
|
|
}
|
|
}
|
|
|
|
export const notificationService = new NotificationService();
|