Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 94x 6x 6x 6x 6x 6x 6x 6x 2x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { request } from "./base";
export type NotificationItem = {
id: string;
userId: string;
proId: string | null;
eventType: string;
category: "enquiry" | "reminder" | "milestone" | "other";
title: string;
body: string | null;
data: Record<string, unknown> | null;
readAt: string | null;
dateCreated: string;
};
export type NotificationsResponse = {
notifications: NotificationItem[];
total: number;
unread_count: number;
page: number;
has_more: boolean;
};
export const notificationsApi = {
getAll(params?: {
category?: string;
search?: string;
page?: number;
limit?: number;
}) {
const qs = new URLSearchParams();
if (params?.category) qs.set("category", params.category);
if (params?.search) qs.set("search", params.search);
if (params?.page !== undefined) qs.set("page", String(params.page));
if (params?.limit !== undefined) qs.set("limit", String(params.limit));
const query = qs.toString();
return request<NotificationsResponse>(
`/api/notifications${query ? `?${query}` : ""}`,
);
},
getUnreadCount() {
return request<{ count: number }>("/api/notifications/unread-count");
},
markAsRead(id: string) {
return request<NotificationItem>(`/api/notifications/${id}/read`, {
method: "PATCH",
});
},
markAllAsRead(category?: string) {
const qs = category ? `?category=${encodeURIComponent(category)}` : "";
return request<{ updated: number }>(`/api/notifications/read-all${qs}`, {
method: "PATCH",
});
},
delete(id: string) {
return request<{ deleted: boolean }>(`/api/notifications/${id}`, {
method: "DELETE",
});
},
deleteBulk(ids: string[]) {
return request<{ deleted: number }>("/api/notifications/bulk", {
method: "DELETE",
body: { ids },
});
},
getSubscriptions() {
return request<unknown[]>("/api/notifications/subscriptions");
},
subscribe(data: {
endpoint: string;
p256dh: string;
auth: string;
}) {
return request<{ id: string }>("/api/notifications/subscriptions", {
method: "POST",
body: data,
});
},
unsubscribe(endpoint: string) {
return request<{ deleted: boolean }>("/api/notifications/subscriptions", {
method: "DELETE",
body: { endpoint },
});
},
getVapidPublicKey() {
return request<{ publicKey: string }>("/api/push/vapid-public-key");
},
testInApp(data: { type: string; title: string; body?: string; url?: string; targetUserId?: string }) {
return request<{ notification: NotificationItem }>("/api/notifications/test/in-app", {
method: "POST",
body: data,
});
},
testPush(data: { type: string; title: string; body?: string; url?: string; targetUserId?: string }) {
return request<{ sent: number; failed: number; details: unknown[] }>("/api/notifications/test/push", {
method: "POST",
body: data,
});
},
testRevokeAll() {
return request<{ deleted: number }>(
"/api/notifications/test/subscriptions",
{ method: "DELETE" },
);
},
};
|