mirror of
https://github.com/rjNemo/melon_frontend
synced 2026-06-09 20:06:39 +00:00
cleanup
This commit is contained in:
parent
5dd137b87e
commit
01dce1b76a
5 changed files with 22 additions and 20 deletions
|
|
@ -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<number>('/bills', data);
|
||||
const { data: response } = await client.post<number>(billsURL, data);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateBill = async (id: number, data: BillFormType): Promise<Response<void>> => {
|
||||
try {
|
||||
const { data: response } = await client.put<void>(`/bills/${id}`, data);
|
||||
const { data: response } = await client.put<void>(`${billsURL}/${id}`, data);
|
||||
return { data: response };
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return { error };
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchOneBill = async (id: number): Promise<Response<Bill>> => {
|
||||
try {
|
||||
const { data } = await client.get<Bill>(`/bills/${id}`);
|
||||
const { data } = await client.get<Bill>(`${billsURL}/${id}`);
|
||||
return { data: billFrom(data) };
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return { error };
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchAllBills = async () => {
|
||||
try {
|
||||
const { data } = await client.get<Bill[]>('/bills');
|
||||
const { data } = await client.get<Bill[]>(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<boolean>(`/bills/${id}/send`);
|
||||
const { data } = await client.post<boolean>(`${billsURL}/${id}/send`);
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
|
|
|||
|
|
@ -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<T> = {
|
||||
data?: T;
|
||||
|
|
|
|||
|
|
@ -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<Response<Report>> => {
|
||||
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<Report>(queryURL);
|
||||
const { data } = await client.get<Report>(reportsURL, { params });
|
||||
return {
|
||||
data: {
|
||||
// @ts-ignore
|
||||
|
|
|
|||
|
|
@ -15,4 +15,3 @@ ReactDOM.render(
|
|||
);
|
||||
|
||||
reportWebVitals();
|
||||
export { enumToList } from './lib/enums';
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
Loading…
Reference in a new issue