notification admin
This commit is contained in:
@@ -1,18 +1,35 @@
|
||||
import axios from "../../../config/axios";
|
||||
import type {
|
||||
NotificationsResponseType,
|
||||
UnseenCountResponseType,
|
||||
} from "../types/NotificationTypes";
|
||||
|
||||
export const getNotifications = async (
|
||||
page: number,
|
||||
status: "all" | "read" | "unread"
|
||||
) => {
|
||||
pageOrCursor: number | string,
|
||||
status: "all" | "read" | "unread",
|
||||
): Promise<NotificationsResponseType> => {
|
||||
let query = ``;
|
||||
if (status !== "all") {
|
||||
query = `&isRead=${status === "read" ? 1 : 0}`;
|
||||
query = `&status=${status === "read" ? "seen" : "unseen"}`;
|
||||
}
|
||||
const { data } = await axios.get(`/notifications?page=${page}${query}`);
|
||||
const pageParam =
|
||||
typeof pageOrCursor === "number"
|
||||
? `page=${pageOrCursor}`
|
||||
: `cursor=${encodeURIComponent(pageOrCursor)}`;
|
||||
const { data } = await axios.get<NotificationsResponseType>(
|
||||
`/admin/notifications?${pageParam}${query}&limit=10`,
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const readAll = async () => {
|
||||
const { data } = await axios.patch(`/notifications/read-all`);
|
||||
const { data } = await axios.put(`/admin/notifications/read/all`);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getUnseenCount = async (): Promise<UnseenCountResponseType> => {
|
||||
const { data } = await axios.get<UnseenCountResponseType>(
|
||||
`/admin/notifications/unseen-count`,
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user