import OrderappClientApi from './index' import apiOrderToAppOrder from '../../libs/apiOrderToAppOrder' import appBatchToApiBatch from '../../libs/appBatchToApiBatch' export default class OrderApi { api: OrderappClientApi constructor (api: OrderappClientApi) { this.api = api } async getOrder (orderId: string): Promise { const endpoint = `/c/order/${orderId}` const response = await this.api.axiosGo.get(endpoint) return apiOrderToAppOrder(response.data) } async getOrders ({ merchantId, table, status, isFilteredByMe = false, limit = 10, valid = 'true,false', withinCutoffTime = false, }: IClientOrderRequestQuery): Promise { const endpoint = '/c/order' const params = { me: isFilteredByMe, merchantID: merchantId, table, status, valid, page: 1, size: limit, ...withinCutoffTime && { withinCutoffTime: true }, } const response = await this.api.axiosGo.get(endpoint, { params }) return response.data.map(apiOrderToAppOrder) } async createOrder (data: IAddOrderRequestData): Promise { const endpoint = '/c/order' const response = await this.api.axiosGo.post(endpoint, data) return apiOrderToAppOrder(response.data) } async submitBatch (params: ISubmitBatchParams): Promise { const data = appBatchToApiBatch(params) const endpoint = `/c/order/${params.orderId}/submit` const response = await this.api.axiosGo.post(endpoint, data) return apiOrderToAppOrder(response.data) } async requestPaying (orderId: string, payment: string): Promise { const endpoint = `/c/order/${orderId}/pay` const response = await this.api.axiosGo.put(endpoint, payment) return apiOrderToAppOrder(response.data) } async requestService (orderId: string): Promise { const endpoint = `/c/order/${orderId}/service` const response = await this.api.axiosGo.put(endpoint) return apiOrderToAppOrder(response.data) } async getRecentPaymentInfo (): Promise { const response = await this.api.axiosGo.get('/c/payment/recent') return response.data } async createWechatPayment (data: ICreateWechatPaymentRequestData): Promise { const response = await this.api.axiosNode.post('/c/payment/qfpay/wechatpay', data) return response.data } }