All files / src/api/modules customer.ts

100% Statements 3/3
100% Branches 4/4
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                            4x 11x                
import type { Customer } from '../types'
import { get } from '../http'
import { CUSTOMER_STAGES } from '../enums'
import { pickEnum } from '@/utils/number'
 
// 后端 /c/customer/list 返回体(com.yd.csf.service.vo.ReferrerCustomerVO)
interface CustomerDTO {
  name: string
  stage: string                    // 8 态语义码
  productName: string
  mobile?: string | null
}
 
export async function fetchCustomers(): Promise<Customer[]> {
  const list = await get<CustomerDTO[]>('/c/customer/list')
  return (list ?? []).map((dto) => ({
    name: dto.name,
    // 后端若新增阶段码,降级为 UNKNOWN,而不是让 'customerStage.XXX' 原文露到界面
    stage: pickEnum(dto.stage, CUSTOMER_STAGES, 'UNKNOWN'),
    productName: dto.productName,
    mobile: dto.mobile ?? ''
  }))
}