保誠-保戶業務員媒合平台
Tomas
2021-12-22 847792a08f17d7b2a6c6ef90aa9e956cee671da3
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
import { http } from "./httpClient";
 
import { ClientInfo } from "../models/client.model";
import { AppointmentDetail } from "../models/appointment.model";
 
class AppointmentService {
 
  // 取得所有預約清單
  async getMyAppointmentList(): Promise<ClientInfo[]> {
    return http.get('/consultant/getMyAppointment').then((res) => {
      const hasNewAppointment = res.data.find((appointment: ClientInfo) => !appointment.consultantViewTime);
      if (hasNewAppointment) {
        this.viewAllAppointment();
      }
      return res.data;
    });
  }
 
  private viewAllAppointment(): void {
    http.post('/consultant/record/allAppointmentsView').then();
  }
 
  // 標記為已聯絡
  markAsContact(appointmentId: number): Promise<void> {
      // TODO: 跟後端確認,這裡的 API 不應該傳回 void, 而是應該是更新後的資料 - Ben 2021/11/16
      // return http.post('/appointment/markAsContacted/'+appointmentId, undefined, {headers})
      //         .then(res => res.data)
      return http.post(`/appointment/markAsContacted/${appointmentId}`);
  }
 
  // 讀取預約單時觸發,紀錄讀取預約單時間
  recordRead(appointmentId: number): Promise<void> {
    return http.post(`/appointment/recordRead/${appointmentId}`);
  }
 
  // 取得預約單細節
  async getAppointmentDetail(appointmentId: number):Promise<AppointmentDetail> {
    return http.get(`/appointment/getDetail/${appointmentId}`).then((res) => res.data);
  }
 
  // 取消預約
  cancelAppointment(appointmentId: number): Promise<void> {
    return http.delete(`/appointment/${appointmentId}`);
  }
 
}
 
export default new AppointmentService();