Files
workavia-drive/twake/frontend/src/app/features/users/api/user-notification-api-client.ts
T
Montassar Ghanmy d91a13e2cc 🔄 Rename all "twake" instances to "tdrive"
🔄 Rename all "twake" instances to "tdrive"
2023-04-10 14:12:00 +01:00

45 lines
1.8 KiB
TypeScript

import Api from '../../global/framework/api-service';
import { NotificationType } from 'app/features/users/types/notification-types';
import { TdriveService } from '../../global/framework/registry-decorator-service';
import { WebsocketRoom } from 'app/features/global/types/websocket-types';
@TdriveService('UserNotificationAPIClientService')
class UserNotificationAPIClient {
private realtime: WebsocketRoom = { room: '', token: '' };
websocket(): WebsocketRoom {
return this.realtime;
}
async getAllCompaniesBadges(): Promise<NotificationType[]> {
const response = await Api.get<{ resources: NotificationType[]; websockets: WebsocketRoom[] }>(
'/internal/services/notifications/v1/badges?limit=1000&websockets=1&all_companies=true',
);
if (response.websockets) this.realtime = response.websockets[0];
return response.resources ? response.resources : [];
}
async getCompanyBadges(companyId: string): Promise<NotificationType[]> {
const response = await Api.get<{ resources: NotificationType[]; websockets: WebsocketRoom[] }>(
'/internal/services/notifications/v1/badges?limit=1000&websockets=1&company_id=' + companyId,
);
if (response.websockets) this.realtime = response.websockets[0];
return response.resources ? response.resources : [];
}
async acknowledge(notification: NotificationType): Promise<void> {
const { message_id, channel_id, company_id, thread_id, workspace_id } = notification;
await Api.post<{ message_id: string, thread_id: string, channel_id: string, workspace_id: string}, boolean>(
`/internal/services/notifications/v1/badges/${company_id}/acknowledge`,
{
channel_id,
workspace_id,
thread_id,
message_id,
}
);
}
}
export default new UserNotificationAPIClient();