refactor: bill aggregate

This commit is contained in:
Ruidy 2021-07-28 11:41:25 +02:00
parent e8b30c868f
commit 756e2072d5
3 changed files with 44 additions and 43 deletions

View file

@ -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
View 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
}

View file

@ -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);