@bit-ui-libs/common
Version:
This library was generated with [Nx](https://nx.dev).
105 lines (88 loc) • 3.69 kB
text/typescript
import * as qs from 'qs';
import { BaseService } from '../api/services/base-service';
import { PagedResponse } from '../common';
import {
EndUserNotificationEvent,
EndUserNotificationEventNameEnum,
Notification,
NotificationStatusEnum,
} from './interfaces';
import {
RegisterPushNotificationTokenRequest,
RegisterPushNotificationTokenResponse,
SearchEndUserNotificationEventsRequest,
SearchNotificationsRequest,
SendMultiPushRequest,
SendSinglePushRequest,
UpdateEndUserNotificationEventsRequest,
UpdateNotificationStatusRequest,
} from './notification.service.interfaces';
export class NotificationService extends BaseService {
private notifApiUrl = `${this.apiUrl}/notifications/v1/notifications`;
searchNotifications(req?: SearchNotificationsRequest) {
return this.get<PagedResponse<Notification>>(`${this.apiUrl}/notifications/v1/notifications`, req);
}
listNotifications(req?: SearchNotificationsRequest) {
return this.get<Notification[]>(`${this.apiUrl}/notifications/v1/notifications/list`, req);
}
searchAdminNotifications(req?: SearchNotificationsRequest) {
return this.get<PagedResponse<Notification>>(`${this.apiUrl}/notifications/v1/admin-notifications`, req);
}
listAdminNotifications(req?: SearchNotificationsRequest) {
return this.get<Notification[]>(`${this.apiUrl}/notifications/v1/admin-notifications/list`, req);
}
getNotificationById(id: string) {
return this.get<Notification>(`${this.apiUrl}/notifications/v1/notifications/${id}`);
}
deleteNotifications(ids: string[]) {
return this.delete<void>(
`${this.apiUrl}/notifications/v1/notifications`,
{ ids },
{ paramsSerializer: (p) => qs.stringify(p) }
);
}
updateNotificationStatus(id: string, status: NotificationStatusEnum) {
const req: UpdateNotificationStatusRequest = { status };
return this.patch<Notification, UpdateNotificationStatusRequest>(
`${this.apiUrl}/notifications/v1/notifications/${id}/status`,
req
);
}
registerPushNotificationToken(req: RegisterPushNotificationTokenRequest) {
return this.post<RegisterPushNotificationTokenResponse, RegisterPushNotificationTokenRequest>(
`${this.apiUrl}/notifications/v1/push/register`,
req
);
}
testSinglePush(req: SendSinglePushRequest) {
return this.post<void, SendSinglePushRequest>(`${this.apiUrl}/notifications/v1/push/test-single-push`, req);
}
testMultiPush(req: SendMultiPushRequest) {
return this.post<void, SendMultiPushRequest>(`${this.apiUrl}/notifications/v1/push/test-multi-push`, req);
}
searchEndUserEvents(req?: SearchEndUserNotificationEventsRequest) {
return this.get<PagedResponse<EndUserNotificationEvent>>(`${this.notifApiUrl}/end-user-events`, req);
}
listEndUserEvents(req?: SearchEndUserNotificationEventsRequest) {
return this.get<EndUserNotificationEvent[]>(`${this.notifApiUrl}/end-user-events/list`, req);
}
updateEndUserEvents(name: EndUserNotificationEventNameEnum, req: UpdateEndUserNotificationEventsRequest) {
return this.put<EndUserNotificationEvent, UpdateEndUserNotificationEventsRequest>(
`${this.notifApiUrl}/end-user-events/${name}`,
req
);
}
updateAdminNotificationStatus(id: string, status: NotificationStatusEnum) {
const req: UpdateNotificationStatusRequest = { status };
return this.patch<Notification, UpdateNotificationStatusRequest>(
`${this.apiUrl}/notifications/v1/admin-notifications/${id}/status`,
req
);
}
clearAdminNotification() {
return this.post<boolean, object>(
`${this.apiUrl}/notifications/v1/admin-notifications/clear`,
{}
);
}
}