Commit d5f3e16d authored by Alex Segers's avatar Alex Segers

[AFP-135] 🗃 Add paginated & filtered orders method to orders service (@asegers)

parent b1350762
import orderList from './mock-order-data'
import { Order } from 'Order';
import { OrdersRequestBody } from 'ManagerRequests'
import Axios, { AxiosError } from 'axios'
import { sleep } from 'utils'
const BASE_PATH = '/api/orders'
export const allOrders = () => {
const apiUrl = 'http://localhost:8080/api/orders';
......@@ -10,8 +14,23 @@ export const orderById = (apiUrl: string) => {
return fetch(apiUrl).then((response) => response.json())
}
export const orders = async (body: OrdersRequestBody): Promise<Order[]> => {
try {
console.log(JSON.stringify(body, null, 3))
debugger
await sleep(1000)
const response = await Axios.post(`${BASE_PATH}/filtered`, body)
console.log(response.data)
return response.data;
} catch (error) {
const { response } = error as AxiosError;
console.error('`OrderService#orders` FAILED TO FETCH ORDERS: ', response)
return [];
}
}
export default {
allOrders,
orderById
orderById,
orders
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment