65 lines
1.4 KiB
TypeScript
65 lines
1.4 KiB
TypeScript
import apiClient from './authApi';
|
|
|
|
export interface Notification {
|
|
notificationId: string;
|
|
userId: string;
|
|
requestId?: string;
|
|
notificationType: string;
|
|
title: string;
|
|
message: string;
|
|
isRead: boolean;
|
|
priority: 'LOW' | 'MEDIUM' | 'HIGH' | 'URGENT';
|
|
actionUrl?: string;
|
|
actionRequired: boolean;
|
|
metadata?: any;
|
|
sentVia: string[];
|
|
readAt?: string;
|
|
createdAt: string;
|
|
}
|
|
|
|
class NotificationApi {
|
|
/**
|
|
* Get user's notifications
|
|
*/
|
|
async list(params?: { page?: number; limit?: number; unreadOnly?: boolean }) {
|
|
const response = await apiClient.get('/notifications', { params });
|
|
return response.data;
|
|
}
|
|
|
|
/**
|
|
* Get unread count
|
|
*/
|
|
async getUnreadCount() {
|
|
const response = await apiClient.get('/notifications/unread-count');
|
|
return response.data.data.unreadCount;
|
|
}
|
|
|
|
/**
|
|
* Mark notification as read
|
|
*/
|
|
async markAsRead(notificationId: string) {
|
|
const response = await apiClient.patch(`/notifications/${notificationId}/read`);
|
|
return response.data;
|
|
}
|
|
|
|
/**
|
|
* Mark all as read
|
|
*/
|
|
async markAllAsRead() {
|
|
const response = await apiClient.post('/notifications/mark-all-read');
|
|
return response.data;
|
|
}
|
|
|
|
/**
|
|
* Delete notification
|
|
*/
|
|
async delete(notificationId: string) {
|
|
const response = await apiClient.delete(`/notifications/${notificationId}`);
|
|
return response.data;
|
|
}
|
|
}
|
|
|
|
export const notificationApi = new NotificationApi();
|
|
export default notificationApi;
|
|
|