-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathNotificationsRepository.ts
More file actions
57 lines (52 loc) · 2.11 KB
/
Copy pathNotificationsRepository.ts
File metadata and controls
57 lines (52 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { ApiRepository } from '../../../core/infra/repositories/ApiRepository'
import { INotificationsRepository } from '../../domain/repositories/INotificationsRepository'
import { Notification } from '../../domain/models/Notification'
import { NotificationPayload } from '../transformers/NotificationPayload'
export class NotificationsRepository extends ApiRepository implements INotificationsRepository {
private readonly notificationsResourceName: string = 'notifications'
public async getAllNotificationsByUser(
inAppNotificationFormat?: boolean
): Promise<Notification[]> {
const queryParams = inAppNotificationFormat ? { inAppNotificationFormat: 'true' } : undefined
return this.doGet(
this.buildApiEndpoint(this.notificationsResourceName, 'all'),
true,
queryParams
)
.then((response) => {
const notifications = response.data.data.notifications
return notifications.map((notification: NotificationPayload) => {
const { dataverseDisplayName, dataverseAlias, ...restNotification } = notification
return {
...restNotification,
...(dataverseDisplayName && { collectionDisplayName: dataverseDisplayName }),
...(dataverseAlias && { collectionAlias: dataverseAlias })
}
}) as Notification[]
})
.catch((error) => {
throw error
})
}
public async deleteNotification(notificationId: number): Promise<void> {
return this.doDelete(
this.buildApiEndpoint(this.notificationsResourceName, notificationId.toString())
)
.then(() => undefined)
.catch((error) => {
throw error
})
}
public async getUnreadNotificationsCount(): Promise<number> {
return this.doGet(
this.buildApiEndpoint(this.notificationsResourceName, 'unreadCount'),
true
).then((response) => response.data.data.unreadCount as number)
}
public async markNotificationAsRead(notificationId: number): Promise<void> {
return this.doPut(
this.buildApiEndpoint(this.notificationsResourceName, 'markAsRead', notificationId),
{}
).then(() => undefined)
}
}