feat: migrate app routes and business modules

This commit is contained in:
2026-08-12 18:22:59 +08:00
parent 555aa00043
commit cc706378c2
247 changed files with 28623 additions and 14988 deletions
+82
View File
@@ -0,0 +1,82 @@
import { hasRemoteConfig } from '@/utils/runtime-config.js'
import {
normalizeNotificationDetail,
normalizeNotifications
} from './notification-contract.js'
import { normalizeResourcePathId } from './request-normalizers.js'
import {
createRequestError,
requestStrict
} from './request-client.js'
const requireRemoteNotifications = (label, operation = '读取') => {
if (hasRemoteConfig()) return
throw createRequestError(
`${label}${operation}需要真实服务,当前本地预览不会伪造结果`,
operation === '读取' ? 'REMOTE_READ_REQUIRED' : 'REMOTE_WRITE_REQUIRED'
)
}
export const notificationApi = {
async getNotifications(requestOptions = {}) {
requireRemoteNotifications('消息通知')
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, '通知标识')
requireRemoteNotifications('通知详情')
const notificationDetail = await requestStrict({
url: `/genealogy/app/notifications/${normalizedNotificationId}`,
method: 'GET'
}, {
requestController: requestOptions.requestController ?? null
})
return normalizeNotificationDetail(notificationDetail, normalizedNotificationId)
},
async getUnreadNotificationCount(requestOptions = {}) {
requireRemoteNotifications('未读通知数量')
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, '通知标识')
requireRemoteNotifications('通知已读状态', '写入')
await requestStrict({
url: `/genealogy/app/notifications/${normalizedNotificationId}/read`,
method: 'POST'
}, {
requireData: false,
requestController: requestOptions.requestController ?? null
})
return null
},
async markAllNotificationsRead(requestOptions = {}) {
requireRemoteNotifications('全部通知已读状态', '写入')
await requestStrict({
url: '/genealogy/app/notifications/read-all',
method: 'POST'
}, {
requireData: false,
requestController: requestOptions.requestController ?? null
})
return null
}
}