2023-07-18 06:37:55 +00:00
|
|
|
// services
|
|
|
|
import APIService from "services/api.service";
|
|
|
|
// types
|
2023-07-26 06:32:14 +00:00
|
|
|
import type {
|
|
|
|
IUserNotification,
|
|
|
|
INotificationParams,
|
|
|
|
NotificationCount,
|
|
|
|
PaginatedUserNotification,
|
2023-08-28 07:56:38 +00:00
|
|
|
IMarkAllAsReadPayload,
|
2023-07-26 06:32:14 +00:00
|
|
|
} from "types";
|
2023-09-13 14:51:02 +00:00
|
|
|
// helpers
|
|
|
|
import { API_BASE_URL } from "helpers/common.helper";
|
2023-07-18 06:37:55 +00:00
|
|
|
|
|
|
|
class UserNotificationsServices extends APIService {
|
|
|
|
constructor() {
|
2023-09-13 14:51:02 +00:00
|
|
|
super(API_BASE_URL);
|
2023-07-18 06:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async getUserNotifications(
|
|
|
|
workspaceSlug: string,
|
|
|
|
params: INotificationParams
|
|
|
|
): Promise<IUserNotification[]> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/users/notifications`, {
|
|
|
|
params,
|
|
|
|
})
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getUserNotificationDetailById(
|
|
|
|
workspaceSlug: string,
|
|
|
|
notificationId: string
|
|
|
|
): Promise<IUserNotification> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async markUserNotificationAsRead(
|
|
|
|
workspaceSlug: string,
|
|
|
|
notificationId: string
|
|
|
|
): Promise<IUserNotification> {
|
|
|
|
return this.post(`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/read/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async markUserNotificationAsUnread(
|
|
|
|
workspaceSlug: string,
|
|
|
|
notificationId: string
|
|
|
|
): Promise<IUserNotification> {
|
|
|
|
return this.delete(
|
|
|
|
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/read/`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async markUserNotificationAsArchived(
|
|
|
|
workspaceSlug: string,
|
|
|
|
notificationId: string
|
|
|
|
): Promise<IUserNotification> {
|
|
|
|
return this.post(
|
|
|
|
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/archive/`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async markUserNotificationAsUnarchived(
|
|
|
|
workspaceSlug: string,
|
|
|
|
notificationId: string
|
|
|
|
): Promise<IUserNotification> {
|
|
|
|
return this.delete(
|
|
|
|
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/archive/`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async patchUserNotification(
|
|
|
|
workspaceSlug: string,
|
|
|
|
notificationId: string,
|
|
|
|
data: Partial<IUserNotification>
|
|
|
|
): Promise<IUserNotification> {
|
|
|
|
return this.patch(
|
|
|
|
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/`,
|
|
|
|
data
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteUserNotification(workspaceSlug: string, notificationId: string): Promise<any> {
|
|
|
|
return this.delete(`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async subscribeToIssueNotifications(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
2023-07-20 11:54:17 +00:00
|
|
|
issueId: string
|
2023-07-18 06:37:55 +00:00
|
|
|
): Promise<any> {
|
|
|
|
return this.post(
|
2023-07-20 11:54:17 +00:00
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/subscribe/`
|
2023-07-18 06:37:55 +00:00
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getIssueNotificationSubscriptionStatus(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
issueId: string
|
|
|
|
): Promise<{
|
|
|
|
subscribed: boolean;
|
|
|
|
}> {
|
|
|
|
return this.get(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/subscribe/`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async unsubscribeFromIssueNotifications(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
issueId: string
|
|
|
|
): Promise<any> {
|
|
|
|
return this.delete(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/subscribe/`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-26 06:32:14 +00:00
|
|
|
async getUnreadNotificationsCount(workspaceSlug: string): Promise<NotificationCount> {
|
2023-07-18 06:37:55 +00:00
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/users/notifications/unread/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-07-26 06:32:14 +00:00
|
|
|
|
|
|
|
async getNotifications(url: string): Promise<PaginatedUserNotification> {
|
|
|
|
return this.get(url)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-08-28 07:56:38 +00:00
|
|
|
|
|
|
|
async markAllNotificationsAsRead(
|
|
|
|
workspaceSlug: string,
|
|
|
|
payload: IMarkAllAsReadPayload
|
|
|
|
): Promise<any> {
|
|
|
|
return this.post(`/api/workspaces/${workspaceSlug}/users/notifications/mark-all-read/`, {
|
|
|
|
...payload,
|
|
|
|
})
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-07-18 06:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const userNotificationServices = new UserNotificationsServices();
|
|
|
|
|
|
|
|
export default userNotificationServices;
|