Files
2026-04-26 01:53:05 +08:00

45 lines
1.0 KiB
TypeScript

import type { Notification } from "@/lib/types"
import { httpJson } from "./http"
type Paginated<T> = {
items: T[] | null
meta: {
total: number
offset: number
limit: number
}
}
export async function listNotifications(input?: {
offset?: number
limit?: number
}): Promise<Notification[]> {
const offset = input?.offset ?? 0
const limit = input?.limit ?? 50
const searchParams = new URLSearchParams({
offset: String(offset),
limit: String(limit),
})
const res = await httpJson<Paginated<Notification>>(`/api/v1/notifications?${searchParams}`, {
cache: "no-store",
})
return res.items ?? []
}
export async function markNotificationAsRead(notificationId: string): Promise<void> {
await httpJson<unknown>(`/api/v1/notifications/${encodeURIComponent(notificationId)}/read`, {
method: "PUT",
cache: "no-store",
})
}
export async function markAllNotificationsAsRead(): Promise<void> {
await httpJson<unknown>("/api/v1/notifications/read-all", {
method: "PUT",
cache: "no-store",
})
}