From 01dce1b76a524f9dc8669a3c0a158bfb29372772 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Thu, 10 Mar 2022 11:07:29 -0400 Subject: [PATCH] cleanup --- src/api/bills.ts | 15 +++++++-------- src/api/index.ts | 4 ++-- src/api/reports.ts | 18 +++++++++++++----- src/index.tsx | 1 - src/setupTests.ts | 4 ---- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/api/bills.ts b/src/api/bills.ts index 694f3c0..2a6a603 100644 --- a/src/api/bills.ts +++ b/src/api/bills.ts @@ -1,39 +1,38 @@ import { client, Response } from '.'; import { Bill, BillFormType, billFrom } from '../types/bill'; +export const billsURL = '/bills'; + export const createBill = async (data: BillFormType) => { try { - const { data: response } = await client.post('/bills', data); + const { data: response } = await client.post(billsURL, data); return response; } catch (error) { console.error(error); return 0; } }; - export const updateBill = async (id: number, data: BillFormType): Promise> => { try { - const { data: response } = await client.put(`/bills/${id}`, data); + const { data: response } = await client.put(`${billsURL}/${id}`, data); return { data: response }; } catch (error) { console.error(error); return { error }; } }; - export const fetchOneBill = async (id: number): Promise> => { try { - const { data } = await client.get(`/bills/${id}`); + const { data } = await client.get(`${billsURL}/${id}`); return { data: billFrom(data) }; } catch (error) { console.error(error); return { error }; } }; - export const fetchAllBills = async () => { try { - const { data } = await client.get('/bills'); + const { data } = await client.get(billsURL); return data; } catch (error) { console.error(error); @@ -43,7 +42,7 @@ export const fetchAllBills = async () => { export const sendBillAsPDF = async (id: number) => { try { - const { data } = await client.post(`/bills/${id}/send`); + const { data } = await client.post(`${billsURL}/${id}/send`); return data; } catch (error) { console.error(error); diff --git a/src/api/index.ts b/src/api/index.ts index a02300e..5a87218 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,8 +1,8 @@ import axios from 'axios'; -const BASE_URL = process.env.REACT_APP_API_URL; +const baseURL = process.env.REACT_APP_API_URL; -export const client = axios.create({ baseURL: BASE_URL }); +export const client = axios.create({ baseURL }); export type Response = { data?: T; diff --git a/src/api/reports.ts b/src/api/reports.ts index 1fb9925..4eb73d2 100644 --- a/src/api/reports.ts +++ b/src/api/reports.ts @@ -1,19 +1,27 @@ import { client, Response } from '.'; import { Report, ReportFormType, ReportType } from '../types/report'; +export const reportsURL = '/reports'; + export const fetchReport = async ({ type, year, month }: ReportFormType): Promise> => { - const baseQueryURL = `/reports/?report_type=${type}&year=${year}`; - const queryURL = + const params = type === ReportType.monthly && month - ? baseQueryURL.concat(`&month=${month + 1}`) - : baseQueryURL; + ? { + report_type: type, + month: month + 1, + year + } + : { + report_type: type, + year + }; try { - const { data } = await client.get(queryURL); + const { data } = await client.get(reportsURL, { params }); return { data: { // @ts-ignore diff --git a/src/index.tsx b/src/index.tsx index db391d1..15e2882 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -15,4 +15,3 @@ ReactDOM.render( ); reportWebVitals(); -export { enumToList } from './lib/enums'; diff --git a/src/setupTests.ts b/src/setupTests.ts index 8f2609b..7b0828b 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -1,5 +1 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom import '@testing-library/jest-dom';