69 lines
2.2 KiB
JavaScript
69 lines
2.2 KiB
JavaScript
import {
|
|
normalizeNotificationDetail,
|
|
normalizeNotifications
|
|
} from './notification-contract.js'
|
|
import { normalizeResourcePathId } from './request-normalizers.js'
|
|
import {
|
|
createRequestError,
|
|
requestStrict
|
|
} from './request-client.js'
|
|
|
|
export const notificationApi = {
|
|
async getNotifications(requestOptions = {}) {
|
|
const notificationRows = await requestStrict({
|
|
url: '/genealogy/app/notifications',
|
|
method: 'GET'
|
|
}, {
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
return normalizeNotifications(notificationRows)
|
|
},
|
|
|
|
async getNotificationDetail(notificationId, requestOptions = {}) {
|
|
const normalizedNotificationId = normalizeResourcePathId(notificationId, '通知标识')
|
|
const notificationDetail = await requestStrict({
|
|
url: `/genealogy/app/notifications/${normalizedNotificationId}`,
|
|
method: 'GET'
|
|
}, {
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
return normalizeNotificationDetail(notificationDetail, normalizedNotificationId)
|
|
},
|
|
|
|
async getUnreadNotificationCount(requestOptions = {}) {
|
|
const unreadCount = await requestStrict({
|
|
url: '/genealogy/app/notifications/unread-count',
|
|
method: 'GET'
|
|
}, {
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
if (!Number.isSafeInteger(unreadCount) || unreadCount < 0) {
|
|
throw createRequestError('未读通知数量响应无效', 'NOTIFICATION_COUNT_RESPONSE_INVALID')
|
|
}
|
|
return unreadCount
|
|
},
|
|
|
|
async markNotificationRead(notificationId, requestOptions = {}) {
|
|
const normalizedNotificationId = normalizeResourcePathId(notificationId, '通知标识')
|
|
await requestStrict({
|
|
url: `/genealogy/app/notifications/${normalizedNotificationId}/read`,
|
|
method: 'POST'
|
|
}, {
|
|
requireData: false,
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
return null
|
|
},
|
|
|
|
async markAllNotificationsRead(requestOptions = {}) {
|
|
await requestStrict({
|
|
url: '/genealogy/app/notifications/read-all',
|
|
method: 'POST'
|
|
}, {
|
|
requireData: false,
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
return null
|
|
}
|
|
}
|