From 756e2072d58710bf2ee4376e171c56d73c16047e Mon Sep 17 00:00:00 2001 From: Ruidy Date: Wed, 28 Jul 2021 11:41:25 +0200 Subject: [PATCH] refactor: bill aggregate --- src/api/index.ts | 18 +----------- src/types/bill/enums.ts | 26 +++++++++++++++++ src/types/{bill.ts => bill/index.ts} | 43 +++++++++++----------------- 3 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 src/types/bill/enums.ts rename src/types/{bill.ts => bill/index.ts} (52%) diff --git a/src/api/index.ts b/src/api/index.ts index f9b4b14..941d772 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -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 - ({ - 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> => { try { const { data } = await client.get(`/${id}`); diff --git a/src/types/bill/enums.ts b/src/types/bill/enums.ts new file mode 100644 index 0000000..a777c09 --- /dev/null +++ b/src/types/bill/enums.ts @@ -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 +} diff --git a/src/types/bill.ts b/src/types/bill/index.ts similarity index 52% rename from src/types/bill.ts rename to src/types/bill/index.ts index 7cbe1e1..1ff6c0c 100644 --- a/src/types/bill.ts +++ b/src/types/bill/index.ts @@ -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);