mirror of
https://github.com/rjNemo/melon_frontend
synced 2026-06-12 05:16:46 +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 { client, Response } from '.';
|
||||||
import { Bill, BillFormType, billFrom } from '../types/bill';
|
import { Bill, BillFormType, billFrom } from '../types/bill';
|
||||||
|
|
||||||
|
export const billsURL = '/bills';
|
||||||
|
|
||||||
export const createBill = async (data: BillFormType) => {
|
export const createBill = async (data: BillFormType) => {
|
||||||
try {
|
try {
|
||||||
const { data: response } = await client.post<number>('/bills', data);
|
const { data: response } = await client.post<number>(billsURL, data);
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateBill = async (id: number, data: BillFormType): Promise<Response<void>> => {
|
export const updateBill = async (id: number, data: BillFormType): Promise<Response<void>> => {
|
||||||
try {
|
try {
|
||||||
const { data: response } = await client.put<void>(`/bills/${id}`, data);
|
const { data: response } = await client.put<void>(`${billsURL}/${id}`, data);
|
||||||
return { data: response };
|
return { data: response };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return { error };
|
return { error };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchOneBill = async (id: number): Promise<Response<Bill>> => {
|
export const fetchOneBill = async (id: number): Promise<Response<Bill>> => {
|
||||||
try {
|
try {
|
||||||
const { data } = await client.get<Bill>(`/bills/${id}`);
|
const { data } = await client.get<Bill>(`${billsURL}/${id}`);
|
||||||
return { data: billFrom(data) };
|
return { data: billFrom(data) };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return { error };
|
return { error };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchAllBills = async () => {
|
export const fetchAllBills = async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await client.get<Bill[]>('/bills');
|
const { data } = await client.get<Bill[]>(billsURL);
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
@ -43,7 +42,7 @@ export const fetchAllBills = async () => {
|
||||||
|
|
||||||
export const sendBillAsPDF = async (id: number) => {
|
export const sendBillAsPDF = async (id: number) => {
|
||||||
try {
|
try {
|
||||||
const { data } = await client.post<boolean>(`/bills/${id}/send`);
|
const { data } = await client.post<boolean>(`${billsURL}/${id}/send`);
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import axios from 'axios';
|
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> = {
|
export type Response<T> = {
|
||||||
data?: T;
|
data?: T;
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,27 @@
|
||||||
import { client, Response } from '.';
|
import { client, Response } from '.';
|
||||||
import { Report, ReportFormType, ReportType } from '../types/report';
|
import { Report, ReportFormType, ReportType } from '../types/report';
|
||||||
|
|
||||||
|
export const reportsURL = '/reports';
|
||||||
|
|
||||||
export const fetchReport = async ({
|
export const fetchReport = async ({
|
||||||
type,
|
type,
|
||||||
year,
|
year,
|
||||||
month
|
month
|
||||||
}: ReportFormType): Promise<Response<Report>> => {
|
}: ReportFormType): Promise<Response<Report>> => {
|
||||||
const baseQueryURL = `/reports/?report_type=${type}&year=${year}`;
|
const params =
|
||||||
const queryURL =
|
|
||||||
type === ReportType.monthly && month
|
type === ReportType.monthly && month
|
||||||
? baseQueryURL.concat(`&month=${month + 1}`)
|
? {
|
||||||
: baseQueryURL;
|
report_type: type,
|
||||||
|
month: month + 1,
|
||||||
|
year
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
report_type: type,
|
||||||
|
year
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data } = await client.get<Report>(queryURL);
|
const { data } = await client.get<Report>(reportsURL, { params });
|
||||||
return {
|
return {
|
||||||
data: {
|
data: {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,3 @@ ReactDOM.render(
|
||||||
);
|
);
|
||||||
|
|
||||||
reportWebVitals();
|
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';
|
import '@testing-library/jest-dom';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue