import axios from 'axios'; import { Bill, BillForm } from '../types/bill'; const BASE_URL = process.env.REACT_APP_API_URL; const client = axios.create({ baseURL: BASE_URL }); export const createBill = async (data: BillForm) => { try { const { data: response } = await client.post('/', data); return response; } catch (error) { console.error(error); return 0; } }; type Response = { data?: T; error?: any; }; export const fetchOneBill = async (id: number): Promise> => { try { const { data } = await client.get(`/${id}`); return { data }; } catch (error) { console.error(error); return { error }; } }; export const fetchAllBills = async () => { try { const { data } = await client.get('/'); return data; } catch (error) { console.error(error); return [] as Bill[]; } }; export const sendBillAsPDF = async (id: number) => { try { const { data } = await client.post(`/${id}/send`); return data; } catch (error) { console.error(error); return false; } };