2024-12-07 23:40:22 +03:00
|
|
|
import { getConfigValue } from '@brojs/cli';
|
|
|
|
|
|
|
|
enum ArmEndpoints {
|
|
|
|
ORDERS = '/arm/orders',
|
|
|
|
MASTERS = '/arm/masters',
|
|
|
|
}
|
|
|
|
|
|
|
|
const armService = () => {
|
|
|
|
const endpoint = getConfigValue('dry-wash.api');
|
|
|
|
|
2024-12-14 22:27:07 +03:00
|
|
|
const fetchOrders = async ({ date }: { date: Date }) => {
|
|
|
|
const response = await fetch(`${endpoint}${ArmEndpoints.ORDERS}`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ date }),
|
|
|
|
});
|
2024-12-07 23:40:22 +03:00
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`Failed to fetch orders: ${response.status}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return await response.json();
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchMasters = async () => {
|
|
|
|
const response = await fetch(`${endpoint}${ArmEndpoints.MASTERS}`);
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`Failed to fetch masters: ${response.status}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return await response.json();
|
|
|
|
};
|
|
|
|
|
|
|
|
return { fetchOrders, fetchMasters };
|
|
|
|
};
|
|
|
|
|
|
|
|
export { armService, ArmEndpoints };
|