保誠-保戶業務員媒合平台
jack
2023-09-05 3ecee0fa557b7bb9e83b67e289b316f04efa9ce5
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { http } from "./httpClient";
 
import { Consultant } from "~/shared/models/consultant.model";
import { FastQueryParams } from "~/shared/models/quick-filter.model";
import { AgentOfStrictQuery, StrictQueryParams } from "~/shared/models/strict-query.model";
import { AppointmentParams } from "~/shared/models/appointment.model";
 
class QueryConsultantService {
 
  // 推薦保險顧問
  async getRecommendConsultantList(): Promise<Consultant[]> {
    return http.get<Consultant[]>('/consultant/recommend').then((res) => res.data);
  }
 
  // 快速篩選
  async fastQuery(data: FastQueryParams): Promise<Consultant[]> {
    try {
      const response = await http.post<Consultant[]>('/consultant/fastQuery', data);
      if (response !== null) {
        return response.data;
      } else {
        throw new Error('http.post returned null-like value.');
      }
    } catch (error) {
      console.error('An error occurred while performing fast query:', error);
      // 可以在此處處理錯誤或回傳預設值
      throw error;
    }
  }
 
 
  // 嚴選配對
  async strictQuery(data: StrictQueryParams): Promise<AgentOfStrictQuery[]> {
    try {
      const response = await http.post('/consultant/strictQuery', data);
      if (response !== null) {
        return response.data;
      } else {
        throw new Error('http.post returned null-like value.');
      }
    } catch (error) {
      console.error('An error occurred while performing strict query:', error);
      // 可以在此處處理錯誤或回傳預設值
      throw error;
    }
  }
 
 
  // 加入顧問
  async addFavoriteConsultant(addFavoriteConsultantList: AddFavoriteConsultantItem[]) {
    const payload = {
      consultantList: addFavoriteConsultantList
    };
    return http.post('/consultant/favorite', payload);
  }
 
  /**
   * 預約需求
   * @param data 包含預約需求相關資訊的物件
   * @returns 回傳預約需求結果
   */
  async  appointmentDemand(data: AppointmentParams) {
    try {
      // 弱掃Test4: 改為 promise.then 寫法
      return http.post('/appointment/customer/create', data).then((res) => {
        if (res) {
          return res['data'];
        } else {
          throw new Error('http.post returned null-like value.');
        }
      })
    } catch (error) {
      // 可以在此處處理錯誤或回傳預設值
      console.error('An error occurred while creating appointment demand:', error);
      throw error;
    }
  }
 
 
}
 
export default new QueryConsultantService();
 
export interface AddFavoriteConsultantItem {
  agentNo    : string;
  createdTime: string;
}