mirror of
https://github.com/rjNemo/melon_frontend
synced 2026-06-06 02:16:45 +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 { Bill, BillFormType } from '../types/bill';
|
||||
import { Bill, BillFormType, billFrom } from '../types/bill';
|
||||
|
||||
const BASE_URL = process.env.REACT_APP_API_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>> => {
|
||||
try {
|
||||
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 = {
|
||||
name: string;
|
||||
phoneNumber: string;
|
||||
|
|
@ -27,29 +29,18 @@ export interface Bill {
|
|||
paymentStatus: PaymentStatus;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
export 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);
|
||||
Loading…
Reference in a new issue