| | |
| | | import { http } from "./httpClient"; |
| | | |
| | | import { ClientInfo } from "~/shared/models/client.model"; |
| | | import { AppointmentDetail, EditAppointmentParams } from "~/shared/models/appointment.model"; |
| | | import { Appointment, AppointmentMemoInfo, createdMemoInfo, EditAppointmentParams, InterviewRecordInfo, ToCloseAppointment, ToDoneAppointment, ToInformAppointment, updatedMemoInfo, UpdateInterviewRecordInfo } from "~/shared/models/appointment.model"; |
| | | |
| | | class AppointmentService { |
| | | |
| | | // 取得所有預約清單 |
| | | async getMyAppointmentList(): Promise<ClientInfo[]> { |
| | | // 顧問取得所有自己的預約單API |
| | | async getMyAppointmentList(): Promise<Appointment[]> { |
| | | return http.get('/consultant/getMyAppointment').then((res) => { |
| | | const hasNewAppointment = res.data.find((appointment: ClientInfo) => !appointment.consultantViewTime); |
| | | const hasNewAppointment = res.data.find((appointment: Appointment) => !appointment.consultantViewTime); |
| | | if (hasNewAppointment) { |
| | | this.viewAllAppointment(); |
| | | } |
| | |
| | | }); |
| | | } |
| | | |
| | | 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}`); |
| | | // 顧問瀏覽自己所有的預約單紀錄觸發API |
| | | private async viewAllAppointment(): Promise<void> { |
| | | try { |
| | | const response = await http.post('/consultant/record/allAppointmentsView'); |
| | | if (response !== null) { |
| | | } else { |
| | | throw new Error('http.post returned null-like value.'); |
| | | } |
| | | } catch (error) { |
| | | console.error('An error occurred while viewing all appointments:', error); |
| | | throw error; |
| | | } |
| | | } |
| | | |
| | | // 讀取預約單時觸發,紀錄讀取預約單時間 |
| | |
| | | } |
| | | |
| | | // 取得預約單細節 |
| | | async getAppointmentDetail(appointmentId: number):Promise<AppointmentDetail> { |
| | | async getAppointmentDetail(appointmentId: number):Promise<Appointment> { |
| | | return http.get(`/appointment/getDetail/${appointmentId}`).then((res) => res.data); |
| | | } |
| | | |
| | |
| | | return http.put('/appointment', editAppointmentParams); |
| | | } |
| | | |
| | | /** |
| | | * 新增註記 |
| | | * @param memoInfo 包含新增註記相關資訊的物件 |
| | | * @returns 回傳新增的註記資訊 |
| | | */ |
| | | async createMemo(memoInfo: createdMemoInfo): Promise<AppointmentMemoInfo> { |
| | | try { |
| | | const response = await http.post('/appointment/memo/create', memoInfo); |
| | | // 弱掃 test2: 改為判斷 !response |
| | | if (!response) { |
| | | throw new Error('http.post returned null-like value.'); |
| | | } else { |
| | | return response.data; |
| | | } |
| | | } catch (error) { |
| | | // 可以在此處處理錯誤或回傳預設值 |
| | | console.error('An error occurred while creating memo:', error); |
| | | throw error; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 編輯註記 |
| | | * @param memoInfo 包含編輯註記相關資訊的物件 |
| | | * @returns 回傳更新後的註記資訊 |
| | | */ |
| | | async updateMemo(memoInfo: updatedMemoInfo): Promise<AppointmentMemoInfo> { |
| | | try { |
| | | const response = await http.post('/appointment/memo/update', memoInfo); |
| | | if (response !== null) { |
| | | return response.data; |
| | | } else { |
| | | throw new Error('http.post returned null-like value.'); |
| | | } |
| | | } catch (error) { |
| | | // 可以在此處處理錯誤或回傳預設值 |
| | | console.error('An error occurred while updating memo:', error); |
| | | throw error; |
| | | } |
| | | } |
| | | |
| | | |
| | | // 刪除註記 |
| | | deleteMemo(appointmentMemoId: number) { |
| | | return http.delete(`/appointment/memo/${appointmentMemoId}`) |
| | | } |
| | | |
| | | /** |
| | | * 預約單結案, 更新結案明細 |
| | | * @param appointmentInfo 包含結案相關資訊的物件 |
| | | * @returns 回傳結案結果 |
| | | */ |
| | | async closeAppointment(appointmentInfo: ToDoneAppointment | ToCloseAppointment) { |
| | | try { |
| | | const response = await http.post(`/appointment/close`, appointmentInfo); |
| | | if (!response) { |
| | | throw new Error('http.post returned a null-like value.'); |
| | | } else { |
| | | return response.data; |
| | | } |
| | | } catch (error) { |
| | | // 在這裡處理錯誤,例如回傳預設值或記錄錯誤訊息 |
| | | console.error('An error occurred while closing appointment:', error); |
| | | throw error; |
| | | } |
| | | } |
| | | |
| | | |
| | | // 約訪通知 API |
| | | async informAppointment(appointmentInformation: ToInformAppointment) { |
| | | try { |
| | | const response = await http.post(`/notice/send`, appointmentInformation); |
| | | if (response !== null) { |
| | | return response.data; |
| | | } else { |
| | | throw new Error('http.post returned null-like value.'); |
| | | } |
| | | } catch (error) { |
| | | console.error('An error occurred while informing appointment:', error); |
| | | // 可以在此處處理錯誤或回傳預設值 |
| | | throw error; |
| | | } |
| | | } |
| | | |
| | | |
| | | // 新增約訪記錄 |
| | | async createInterviewRecord(interviewRecordInfo: InterviewRecordInfo) { |
| | | try { |
| | | const response = await http.post('/interview_record/create', interviewRecordInfo); |
| | | if (response !== null) { |
| | | return response.data; |
| | | } else { |
| | | throw new Error('http.post returned null-like value.'); |
| | | } |
| | | } catch (error) { |
| | | console.error('An error occurred while creating interview record:', error); |
| | | // 可以在此處處理錯誤或回傳預設值 |
| | | throw error; |
| | | } |
| | | } |
| | | |
| | | // 修改約訪記錄 |
| | | async updateInterviewRecord(updateInterviewRecordInfo: UpdateInterviewRecordInfo) { |
| | | return http.post('/interview_record/update', updateInterviewRecordInfo) |
| | | } |
| | | |
| | | // 刪除約訪記錄 |
| | | async deleteInterviewRecord(interviewRecordId) { |
| | | return http.delete(`/interview_record/${interviewRecordId}`); |
| | | } |
| | | |
| | | // 客戶取得最新預約的未處理預約單 |
| | | async getNotContactAppointment(): Promise<Appointment> { |
| | | return http.get(`/appointment/customer/expiring/newest`).then((res) => res.data); |
| | | } |
| | | |
| | | // 顧問取得未處理預約單數量通知 |
| | | async getPendingAppointmentSum(): Promise<number> { |
| | | return http.get(`/appointment/consultant/pending/sum`).then((res) => res.data) |
| | | } |
| | | |
| | | } |
| | | |
| | | export default new AppointmentService(); |