Files
airz-uniapp/packages/account/services/latest-report.uts
T

21 lines
1.1 KiB
Plaintext
Raw Normal View History

import { requestJson } from '@/services/api.uts'
export type LatestReportEntry = { id: string, status: string }
async function latestAssessment(status: string): Promise<LatestReportEntry | null> {
const result = await requestJson('/assessments', 'GET', { status, limit: '1' })
const items = result['items'] as UTSJSONObject[] | null
if (items == null) throw new Error('评估记录响应不完整')
if (items.length == 0) return null
const id = items[0].getString('assessmentId') ?? ''
if (!/^[1-9][0-9]{0,9}$/.test(id) || items[0].getString('status') != status) throw new Error('评估记录格式错误,请稍后重试')
return { id, status }
}
// 服务端先按成功状态筛选再取最新提交,避免最近一页中的处理中任务遮住更早的报告。
// 账户分包只读取共享API,不导入融资分包代码,也不缓存报告或个人资料。
export async function findLatestReportEntry(): Promise<LatestReportEntry | null> {
const report = await latestAssessment('succeeded')
return report != null ? report : await latestAssessment('processing')
}