mirror of
https://github.com/rjNemo/melon_frontend
synced 2026-06-12 05:16:46 +00:00
refactor: bill aggregate
This commit is contained in:
parent
e8b30c868f
commit
756e2072d5
3 changed files with 44 additions and 43 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Bill, BillFormType } from '../types/bill';
|
import { Bill, BillFormType, billFrom } from '../types/bill';
|
||||||
|
|
||||||
const BASE_URL = process.env.REACT_APP_API_URL;
|
const BASE_URL = process.env.REACT_APP_API_URL;
|
||||||
const client = axios.create({ baseURL: BASE_URL });
|
const client = axios.create({ baseURL: BASE_URL });
|
||||||
|
|
@ -29,22 +29,6 @@ export const updateBill = async (id: number, data: BillFormType): Promise<Respon
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const billFrom = (bill: any): Bill =>
|
|
||||||
({
|
|
||||||
id: bill.id,
|
|
||||||
customers: bill.customers_qty,
|
|
||||||
end: bill.end_date,
|
|
||||||
name: bill.name,
|
|
||||||
paymentMethod: bill.payment_method,
|
|
||||||
paymentStatus: bill.payment_status,
|
|
||||||
phoneNumber: bill.phone_number,
|
|
||||||
platform: bill.platform,
|
|
||||||
price: bill.price,
|
|
||||||
room: bill.room,
|
|
||||||
start: bill.start_date,
|
|
||||||
taxes: bill.with_tax
|
|
||||||
} as Bill);
|
|
||||||
|
|
||||||
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>(`/${id}`);
|
const { data } = await client.get<Bill>(`/${id}`);
|
||||||
|
|
|
||||||
26
src/types/bill/enums.ts
Normal file
26
src/types/bill/enums.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
export enum Room {
|
||||||
|
t2,
|
||||||
|
t3
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Platform {
|
||||||
|
web,
|
||||||
|
booking,
|
||||||
|
airbnb,
|
||||||
|
tripadvisor,
|
||||||
|
perso
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PaymentMethod {
|
||||||
|
card,
|
||||||
|
cash,
|
||||||
|
cheque,
|
||||||
|
transfer
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PaymentStatus {
|
||||||
|
pending,
|
||||||
|
canceled,
|
||||||
|
completed,
|
||||||
|
refund
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { PaymentMethod, PaymentStatus, Platform, Room } from './enums';
|
||||||
|
|
||||||
export type BillFormType = {
|
export type BillFormType = {
|
||||||
name: string;
|
name: string;
|
||||||
phoneNumber: string;
|
phoneNumber: string;
|
||||||
|
|
@ -27,29 +29,18 @@ export interface Bill {
|
||||||
paymentStatus: PaymentStatus;
|
paymentStatus: PaymentStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Room {
|
export const billFrom = (bill: any): Bill =>
|
||||||
t2,
|
({
|
||||||
t3
|
id: bill.id,
|
||||||
}
|
customers: bill.customers_qty,
|
||||||
|
end: bill.end_date,
|
||||||
export enum Platform {
|
name: bill.name,
|
||||||
web,
|
paymentMethod: bill.payment_method,
|
||||||
booking,
|
paymentStatus: bill.payment_status,
|
||||||
airbnb,
|
phoneNumber: bill.phone_number,
|
||||||
tripadvisor,
|
platform: bill.platform,
|
||||||
perso
|
price: bill.price,
|
||||||
}
|
room: bill.room,
|
||||||
|
start: bill.start_date,
|
||||||
export enum PaymentMethod {
|
taxes: bill.with_tax
|
||||||
card,
|
} as Bill);
|
||||||
cash,
|
|
||||||
cheque,
|
|
||||||
transfer
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum PaymentStatus {
|
|
||||||
pending,
|
|
||||||
canceled,
|
|
||||||
completed,
|
|
||||||
refund
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue