import { CreateOrderRequestType, DeleteOrderRequestType, ListOrdersRequestParams, Order, OrderBatchUpdateRequestType, OrderBatchUpdateResponseType, OrderByIdRequestType, UpdateOrderRequestType, } from './types'; import { AxiosInstance } from 'axios'; export default class Orders { private readonly client: AxiosInstance; constructor(client: AxiosInstance) { this.client = client; } async create(data: CreateOrderRequestType) { const response = await this.client.post('orders', data); return response.data; } async getById(id: OrderByIdRequestType) { const response = await this.client.get(`orders/${id.id}`, { params: id.params, }); return response.data; } async updateById({ id, data }: UpdateOrderRequestType) { const response = await this.client.put(`orders/${id}`, data); return response.data; } async deleteById({ id, data }: DeleteOrderRequestType) { const response = await this.client.delete(`orders/${id}`, { data, }); return response.data; } async list( params?: ListOrdersRequestParams ): Promise<{ data: Order[]; count: number; totalPages: number; }> { const response = await this.client.get('orders', { params }); return { data: response.data, count: response.headers['x-wp-total'], totalPages: response.headers['x-wp-totalpages'], }; } async batch(data: OrderBatchUpdateRequestType) { const response = await this.client.post( 'orders/batch', data ); return response.data; } }