Files
edr-platform/apps/edr-freight-web/portal/src/features/notifications/notificationsApi.ts
2026-07-06 11:58:06 +03:00

34 lines
1.0 KiB
TypeScript

import type { NotificationListResult } from "@edr/types";
import { client } from "@/utils/api";
export interface ListNotificationsParams {
page?: number;
limit?: number;
isRead?: boolean;
}
/**
* Portal notification REST calls. The portal axios `client` returns the raw
* response, and the API wraps payloads in a `{ success, data }` envelope — so we
* unwrap `.data.data` here (same convention as the other portal services).
*/
export const notificationsApi = {
list: async (
params: ListNotificationsParams = {},
): Promise<NotificationListResult> => {
const { data } = await client.get("/api/notifications", { params });
return data.data;
},
unreadCount: async (): Promise<number> => {
const { data } = await client.get("/api/notifications/unread-count");
return data.data.unreadCount;
},
markRead: async (id: string): Promise<void> => {
await client.patch(`/api/notifications/${id}/read`);
},
markAllRead: async (): Promise<void> => {
await client.post("/api/notifications/read-all");
},
};