60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { httpGetRequest, httpPutRequest, APIUrlGenerator } from "@/utils/baseHttpService";
|
|
import { API_ROUTES } from "@/constant/routes";
|
|
import {
|
|
AdminNotificationsResponse,
|
|
AdminNotificationsUnreadResponse,
|
|
AdminNotificationsCountResponse,
|
|
MarkNotificationReadResponse,
|
|
AdminNotificationsFilters,
|
|
} from "./_models";
|
|
|
|
export const getAdminNotifications = async (
|
|
filters?: AdminNotificationsFilters
|
|
): Promise<AdminNotificationsResponse> => {
|
|
const queryParams: Record<string, string | number> = {};
|
|
|
|
if (filters?.offset !== undefined) queryParams.offset = filters.offset;
|
|
if (filters?.limit !== undefined) queryParams.limit = filters.limit;
|
|
|
|
const response = await httpGetRequest<AdminNotificationsResponse>(
|
|
APIUrlGenerator(API_ROUTES.GET_ADMIN_NOTIFICATIONS, queryParams)
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
export const getAdminNotificationsUnread = async (
|
|
limit?: number
|
|
): Promise<AdminNotificationsUnreadResponse> => {
|
|
const queryParams: Record<string, number> = {};
|
|
|
|
if (limit !== undefined) queryParams.limit = limit;
|
|
|
|
const response = await httpGetRequest<AdminNotificationsUnreadResponse>(
|
|
APIUrlGenerator(API_ROUTES.GET_ADMIN_NOTIFICATIONS_UNREAD, queryParams)
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
export const getAdminNotificationsCount = async (): Promise<AdminNotificationsCountResponse> => {
|
|
const response = await httpGetRequest<AdminNotificationsCountResponse>(
|
|
APIUrlGenerator(API_ROUTES.GET_ADMIN_NOTIFICATIONS_COUNT)
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
export const markNotificationRead = async (
|
|
notificationId: number
|
|
): Promise<MarkNotificationReadResponse> => {
|
|
const response = await httpPutRequest<MarkNotificationReadResponse>(
|
|
APIUrlGenerator(API_ROUTES.MARK_NOTIFICATION_READ(notificationId.toString()))
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
export const markAllNotificationsRead = async (): Promise<MarkNotificationReadResponse> => {
|
|
const response = await httpPutRequest<MarkNotificationReadResponse>(
|
|
APIUrlGenerator(API_ROUTES.MARK_ALL_NOTIFICATIONS_READ)
|
|
);
|
|
return response.data;
|
|
};
|