2021-06-09 14:32:17 +00:00
|
|
|
import { AxiosPromise } from "axios";
|
|
|
|
|
import Api from "./Api";
|
|
|
|
|
import { ApiResponse } from "./ApiResponses";
|
|
|
|
|
|
2021-06-23 15:42:07 +00:00
|
|
|
class NotificationsApi extends Api {
|
2021-06-09 14:32:17 +00:00
|
|
|
static baseURL = "v1/notifications";
|
2021-06-23 15:42:07 +00:00
|
|
|
static markAsReadURL = `${NotificationsApi.baseURL}/isRead`;
|
|
|
|
|
static markAllAsReadURL = `${NotificationsApi.markAsReadURL}/all`;
|
|
|
|
|
static fetchUnreadNotificationsCountURL = `${NotificationsApi.baseURL}/count/unread`;
|
2021-06-09 14:32:17 +00:00
|
|
|
|
2021-06-23 15:42:07 +00:00
|
|
|
static fetchNotifications(beforeDate?: string): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(NotificationsApi.baseURL, beforeDate ? { beforeDate } : {});
|
2021-06-09 14:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static markAllNotificationsAsRead(): AxiosPromise<ApiResponse> {
|
2021-06-23 15:42:07 +00:00
|
|
|
return Api.patch(NotificationsApi.markAllAsReadURL, { isRead: true });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static fetchUnreadNotificationsCount(): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(NotificationsApi.fetchUnreadNotificationsCountURL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static markNotificationsAsRead(
|
|
|
|
|
ids: Array<string>,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.patch(NotificationsApi.markAsReadURL, {
|
|
|
|
|
isRead: true,
|
|
|
|
|
idList: ids,
|
|
|
|
|
});
|
2021-06-09 14:32:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 15:42:07 +00:00
|
|
|
export default NotificationsApi;
|