52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import client from "./client";
|
|
|
|
// ── Types ───────────────────────────────────────────────────────────
|
|
|
|
export interface NotificationItem {
|
|
id: string;
|
|
user_id: string;
|
|
type: string;
|
|
title: string;
|
|
message: string | null;
|
|
entity_type: string | null;
|
|
entity_id: string | null;
|
|
read: boolean;
|
|
created_at: string | null;
|
|
}
|
|
|
|
export interface UnreadCount {
|
|
unread_count: number;
|
|
}
|
|
|
|
// ── API ─────────────────────────────────────────────────────────────
|
|
|
|
/** Fetch notifications for the current user (paginated). */
|
|
export async function getNotifications(
|
|
offset = 0,
|
|
limit = 20,
|
|
): Promise<NotificationItem[]> {
|
|
const { data } = await client.get<NotificationItem[]>(
|
|
`/notifications?offset=${offset}&limit=${limit}`,
|
|
);
|
|
return data;
|
|
}
|
|
|
|
/** Get the unread notification count. */
|
|
export async function getUnreadCount(): Promise<UnreadCount> {
|
|
const { data } = await client.get<UnreadCount>("/notifications/unread-count");
|
|
return data;
|
|
}
|
|
|
|
/** Mark a single notification as read. */
|
|
export async function markAsRead(id: string): Promise<NotificationItem> {
|
|
const { data } = await client.patch<NotificationItem>(
|
|
`/notifications/${id}/read`,
|
|
);
|
|
return data;
|
|
}
|
|
|
|
/** Mark all notifications as read. */
|
|
export async function markAllAsRead(): Promise<void> {
|
|
await client.post("/notifications/read-all");
|
|
}
|