From bce34327a0aa3d6ea8365423df9962c13f256ab4 Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期五, 01 九月 2023 13:59:23 +0800
Subject: [PATCH] Update: 處理弱掃問題:  Trying to await on a null object

---
 PAMapp/shared/services/query-consultant.service.ts |   66 +++++++++++++++++++++++++++++----
 1 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/PAMapp/shared/services/query-consultant.service.ts b/PAMapp/shared/services/query-consultant.service.ts
index a11cd13..23ac24d 100644
--- a/PAMapp/shared/services/query-consultant.service.ts
+++ b/PAMapp/shared/services/query-consultant.service.ts
@@ -14,24 +14,74 @@
 
   // 敹恍�祟�
   async fastQuery(data: FastQueryParams): Promise<Consultant[]> {
-    return http.post<Consultant[]>('/consultant/fastQuery', data).then(res => res.data);
+    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[]>{
-    return http.post('/consultant/strictQuery', data).then((res) => res.data);
+  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(agentNoList: string[]) {
-    return http.post('/consultant/favorite', { agentNoList });
+  async addFavoriteConsultant(addFavoriteConsultantList: AddFavoriteConsultantItem[]) {
+    const payload = {
+      consultantList: addFavoriteConsultantList
+    };
+    return http.post('/consultant/favorite', payload);
   }
 
-  // ����岷���
-  async appointmentDemand(data: AppointmentParams) {
-    return http.post('/appointment/customer/create', data);
+  /**
+   * ����瘙�
+   * @param data ������瘙�����隞�
+   * @returns ������瘙���
+   */
+  async  appointmentDemand(data: AppointmentParams) {
+    try {
+      // 撘望�est4: �� 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;
+}

--
Gitblit v1.8.0