customers.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { http } from '../http/client'
  2. import type {
  3. CustomerDashboardSummary,
  4. CustomerDetailEntity,
  5. CustomerEntity,
  6. PaginatedCustomerList,
  7. } from './contracts'
  8. export type {
  9. CustomerDashboardSummary,
  10. CustomerDetailEntity,
  11. CustomerEntity,
  12. PaginatedCustomerList,
  13. } from './contracts'
  14. export type CustomerUpsertInput = {
  15. name: string
  16. namePronunciation?: string
  17. phone: string
  18. email?: string
  19. birthday?: string
  20. avatar?: string
  21. expectContact?: 'LINE' | 'PHONE' | 'EMAIL' | 'NONE'
  22. hairLength?: 'SHORT' | 'MEDIUM' | 'LONG' | 'UNCONFIRM'
  23. hairTexture?: 'UNCONFIRM' | 'THIN' | 'NORMAL' | 'HARD_CRUDE' | 'CURLY'
  24. notice?: string
  25. allergy?: string
  26. innerRemark?: string
  27. nextFollowDate?: string
  28. recommendVisitDate?: string
  29. firstSuggestHair?: 'AUTO' | 'LONG' | 'MEDIUM' | 'SHORT'
  30. planDate?: string
  31. visitPurpose?: 'CUT_DYE' | 'CUT' | 'DYE' | 'CONSULT_SIM'
  32. trouble?: string
  33. consultContent?: string
  34. expectLook?: string
  35. }
  36. export async function listCustomers(
  37. params: {
  38. page?: number
  39. pageSize?: number
  40. q?: string
  41. visitStatus?: string
  42. followStatus?: string
  43. hairLength?: string
  44. } = {},
  45. ): Promise<PaginatedCustomerList> {
  46. const query = new URLSearchParams()
  47. if (params.page) query.set('page', String(params.page))
  48. if (params.pageSize) query.set('pageSize', String(params.pageSize))
  49. if (params.q) query.set('q', params.q)
  50. if (params.visitStatus) query.set('visitStatus', params.visitStatus)
  51. if (params.followStatus) query.set('followStatus', params.followStatus)
  52. if (params.hairLength) query.set('hairLength', params.hairLength)
  53. const qs = query.toString()
  54. return http.get<PaginatedCustomerList>(`/customers${qs ? `?${qs}` : ''}`)
  55. }
  56. export async function createCustomer(input: CustomerUpsertInput): Promise<CustomerEntity> {
  57. return http.post<CustomerEntity>('/customers', input)
  58. }
  59. export async function getCustomerById(customerId: string): Promise<CustomerDetailEntity> {
  60. return http.get<CustomerDetailEntity>(`/customers/${customerId}`)
  61. }
  62. export async function getCustomerDashboardSummary(): Promise<CustomerDashboardSummary> {
  63. return http.get<CustomerDashboardSummary>('/customers/summary')
  64. }