move CRUD operations to helpers

This commit is contained in:
Thomas Ruoff
2021-06-07 23:32:54 +02:00
parent 865bbb20fa
commit 92477e5325
9 changed files with 102 additions and 93 deletions

View File

@@ -1,11 +1,18 @@
import { MILAGE_TARIFS } from '../db/enums'
import { AdditionalCost } from '../db/bill'
import { AdditionalCost, Bill } from '../db/bill'
import fetch from './fetch'
function roundToCent(amount: number): number {
return Math.round(amount * 100) / 100
}
export function getMilageCosts({ tarif, km }: { tarif: MILAGE_TARIFS; km: number }): number {
export function getMilageCosts({
tarif,
km,
}: {
tarif: MILAGE_TARIFS
km: number
}): number {
if (tarif === MILAGE_TARIFS.NOCHARGE) {
return 0
}
@@ -63,3 +70,23 @@ export function getBillTotal({
return roundToCent(milageCosts + additionalCostsSum)
}
export async function createBill(
bookingUuid: string,
bill: Bill
): Promise<Bill> {
return fetch(`/api/admin/booking/${bookingUuid}/bill`, {
method: 'POST',
body: bill,
})
}
export async function patchBill(
bookingUuid: string,
bill: Bill
): Promise<Bill> {
return fetch(`/api/admin/booking/${bookingUuid}/bill`, {
method: 'POST',
body: bill,
})
}