Files
Novault-Frontend-web/src/services/notificationService.ts

53 lines
1.2 KiB
TypeScript
Raw Normal View History

import api from './api';
export interface Notification {
id: number;
user_id: number;
title: string;
content: string;
type: string;
is_read: boolean;
link?: string;
read_at?: string;
created_at: string;
}
export interface NotificationListResponse {
success: boolean;
data: {
notifications: Notification[];
total: number;
page: number;
limit: number;
};
}
export interface UnreadCountResponse {
success: boolean;
data: {
count: number;
};
}
export const notificationService = {
getNotifications: (page: number = 1, limit: number = 10, isRead?: boolean) => {
const params: Record<string, string | number | boolean> = { page, limit };
if (isRead !== undefined) {
params.is_read = isRead;
}
return api.get<NotificationListResponse>('/notifications', params);
},
getUnreadCount: () => {
return api.get<UnreadCountResponse>('/notifications/unread-count');
},
markAsRead: (id: number) => {
return api.put<{ success: boolean }>(`/notifications/${id}/read`);
},
markAllAsRead: () => {
return api.put<{ success: boolean }>('/notifications/read-all');
}
};