Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Synced from upstream: 8853637e981ed7d8a6cff32bd98e7afe20f54362
119 lines
3.3 KiB
TypeScript
119 lines
3.3 KiB
TypeScript
/* eslint-disable no-useless-catch */
|
|
|
|
import { API_BASE_URL } from "@plane/constants";
|
|
import type {
|
|
TNotificationPaginatedInfo,
|
|
TNotificationPaginatedInfoQueryParams,
|
|
TNotification,
|
|
TUnreadNotificationsCount,
|
|
} from "@plane/types";
|
|
// helpers
|
|
// services
|
|
import { APIService } from "@/services/api.service";
|
|
|
|
export class WorkspaceNotificationService extends APIService {
|
|
constructor() {
|
|
super(API_BASE_URL);
|
|
}
|
|
|
|
async fetchUnreadNotificationsCount(workspaceSlug: string): Promise<TUnreadNotificationsCount | undefined> {
|
|
try {
|
|
const { data } = await this.get(`/api/workspaces/${workspaceSlug}/users/notifications/unread/`);
|
|
return data || undefined;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async fetchNotifications(
|
|
workspaceSlug: string,
|
|
params: TNotificationPaginatedInfoQueryParams
|
|
): Promise<TNotificationPaginatedInfo | undefined> {
|
|
try {
|
|
const { data } = await this.get(`/api/workspaces/${workspaceSlug}/users/notifications`, {
|
|
params,
|
|
});
|
|
return data || undefined;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async updateNotificationById(
|
|
workspaceSlug: string,
|
|
notificationId: string,
|
|
payload: Partial<TNotification>
|
|
): Promise<TNotification | undefined> {
|
|
try {
|
|
const { data } = await this.patch(
|
|
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/`,
|
|
payload
|
|
);
|
|
return data || undefined;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async markNotificationAsRead(workspaceSlug: string, notificationId: string): Promise<TNotification | undefined> {
|
|
try {
|
|
const { data } = await this.post(`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/read/`);
|
|
return data || undefined;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async markNotificationAsUnread(workspaceSlug: string, notificationId: string): Promise<TNotification | undefined> {
|
|
try {
|
|
const { data } = await this.delete(
|
|
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/read/`
|
|
);
|
|
return data || undefined;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async markNotificationAsArchived(workspaceSlug: string, notificationId: string): Promise<TNotification | undefined> {
|
|
try {
|
|
const { data } = await this.post(
|
|
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/archive/`
|
|
);
|
|
return data || undefined;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async markNotificationAsUnArchived(
|
|
workspaceSlug: string,
|
|
notificationId: string
|
|
): Promise<TNotification | undefined> {
|
|
try {
|
|
const { data } = await this.delete(
|
|
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/archive/`
|
|
);
|
|
return data || undefined;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async markAllNotificationsAsRead(
|
|
workspaceSlug: string,
|
|
payload: TNotificationPaginatedInfoQueryParams
|
|
): Promise<TNotification | undefined> {
|
|
try {
|
|
const { data } = await this.post(`/api/workspaces/${workspaceSlug}/users/notifications/mark-all-read/`, payload);
|
|
return data || undefined;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
const workspaceNotificationService = new WorkspaceNotificationService();
|
|
|
|
export default workspaceNotificationService;
|