forked from zolfagharipour/Matcha
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.ts
More file actions
43 lines (38 loc) · 1.24 KB
/
notifications.ts
File metadata and controls
43 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { authFetch } from './authFetch';
export interface Notification {
id: number;
type: string;
content: string | null;
isRead: boolean;
createdAt: string;
metadata: Record<string, unknown> | null;
triggeredBy: { id: string; username: string };
}
export interface NotificationsResponse {
notifications: Notification[];
total: number;
limit: number;
offset: number;
}
export async function apiGetNotifications(params?: {
limit?: number;
offset?: number;
unreadOnly?: boolean;
}): Promise<NotificationsResponse> {
const search = new URLSearchParams();
if (params?.limit != null) search.set('limit', String(params.limit));
if (params?.offset != null) search.set('offset', String(params.offset));
if (params?.unreadOnly === true) search.set('unreadOnly', 'true');
const qs = search.toString();
const url = `/notifications${qs ? `?${qs}` : ''}`;
return authFetch(url);
}
export async function apiGetUnreadCount(): Promise<{ count: number }> {
return authFetch('/notifications/unread-count');
}
export async function apiMarkNotificationsRead(options: {
notificationIds?: number[];
markAll?: boolean;
}): Promise<{ updated: number }> {
return authFetch('/notifications/read', { method: 'PATCH', body: options });
}