All files / src/api/modules pipeline.ts

100% Statements 3/3
100% Branches 2/2
100% Functions 2/2
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                    6x 6x                    
import type { PipelineItem, CommissionStatus } from '../types'
import { get } from '../http'
import { COMMISSION_STATUSES } from '../enums'
import { pickEnum, toNumber } from '@/utils/number'
import { toYearMonth } from '@/utils/date'
 
// 后端 /c/pipeline 返回体(com.yd.csf.service.vo.ReferrerPipelineVO)
interface PipelineDTO {
  expectedFortuneBizId: string
  policyNo: string
  fortunePeriod: number
  fortuneName: string
  payoutDate?: string | null      // yyyy-MM-dd
  stage: string                   // D4.1 四态码
  hkdAmount: number               // 剩余待发折合港币
}
 
export async function fetchPipeline(): Promise<PipelineItem[]> {
  const list = await get<PipelineDTO[]>('/c/pipeline/list')
  return (list ?? []).map((dto) => ({
    id: dto.expectedFortuneBizId,
    policyNo: dto.policyNo,
    // 原先用 payoutDate.slice(0, 7):后端下发非补零日期时 '2026-3-5' 会切成 '2026-3-'
    payoutMonth: toYearMonth(dto.payoutDate),
    expectedAmount: toNumber(dto.hkdAmount),
    currency: 'HKD',
    status: pickEnum<CommissionStatus>(dto.stage, COMMISSION_STATUSES, 'UNKNOWN')
  }))
}