2023-12-14 00:04:07 +00:00
|
|
|
import { createGraphQLClient } from '../createGraphQLClient'
|
2023-11-28 13:18:25 +00:00
|
|
|
import markAllNotificationsAsRead from '../mutation/notifier/mark-all-notifications-as-read'
|
|
|
|
import markNotificationAsRead from '../mutation/notifier/mark-notification-as-read'
|
|
|
|
import loadNotifications from '../query/notifier/notifications-load'
|
2023-11-28 18:04:51 +00:00
|
|
|
import { NotificationsResult, QueryLoad_NotificationsArgs } from '../schema/notifier.gen'
|
2023-11-28 13:18:25 +00:00
|
|
|
|
|
|
|
export const notifierClient = {
|
2023-12-03 10:22:42 +00:00
|
|
|
private: null,
|
2023-12-14 00:04:07 +00:00
|
|
|
connect: (token: string) => (notifierClient.private = createGraphQLClient('notifier', token)),
|
2023-12-03 10:22:42 +00:00
|
|
|
|
2023-11-28 13:18:25 +00:00
|
|
|
getNotifications: async (params: QueryLoad_NotificationsArgs): Promise<NotificationsResult> => {
|
2023-12-03 10:22:42 +00:00
|
|
|
const resp = await notifierClient.private.query(loadNotifications, params).toPromise()
|
2023-11-28 13:18:25 +00:00
|
|
|
return resp.data.load_notifications
|
|
|
|
},
|
|
|
|
markNotificationAsRead: async (notification_id: number): Promise<void> => {
|
2023-12-03 10:22:42 +00:00
|
|
|
await notifierClient.private
|
2023-11-28 13:18:25 +00:00
|
|
|
.mutation(markNotificationAsRead, {
|
|
|
|
notification_id,
|
|
|
|
})
|
|
|
|
.toPromise()
|
|
|
|
},
|
|
|
|
|
|
|
|
markAllNotificationsAsRead: async (): Promise<void> => {
|
2023-12-03 10:22:42 +00:00
|
|
|
await notifierClient.private.mutation(markAllNotificationsAsRead, {}).toPromise()
|
2023-11-28 13:18:25 +00:00
|
|
|
},
|
|
|
|
}
|