refactor(web): unify bills as UIBill, remove BillRecord
This commit is contained in:
45
web/src/lib/models/bill.ts
Normal file
45
web/src/lib/models/bill.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import type { CleanedBill, UpdateBillRequest } from '$lib/api';
|
||||
|
||||
export interface UIBill {
|
||||
id?: string;
|
||||
time: string;
|
||||
category: string;
|
||||
merchant: string;
|
||||
description?: string;
|
||||
incomeExpense: string;
|
||||
amount: number;
|
||||
paymentMethod?: string;
|
||||
status?: string;
|
||||
remark?: string;
|
||||
reviewLevel?: string;
|
||||
}
|
||||
|
||||
export function cleanedBillToUIBill(bill: CleanedBill): UIBill {
|
||||
return {
|
||||
id: bill.id,
|
||||
time: bill.time,
|
||||
category: bill.category,
|
||||
merchant: bill.merchant,
|
||||
description: bill.description || '',
|
||||
incomeExpense: bill.income_expense,
|
||||
amount: bill.amount,
|
||||
paymentMethod: bill.pay_method || '',
|
||||
status: bill.status || '',
|
||||
remark: bill.remark || '',
|
||||
reviewLevel: bill.review_level || '',
|
||||
};
|
||||
}
|
||||
|
||||
export function uiBillToUpdateBillRequest(bill: UIBill): UpdateBillRequest {
|
||||
return {
|
||||
time: bill.time,
|
||||
category: bill.category,
|
||||
merchant: bill.merchant,
|
||||
description: bill.description,
|
||||
income_expense: bill.incomeExpense,
|
||||
amount: bill.amount,
|
||||
pay_method: bill.paymentMethod,
|
||||
status: bill.status,
|
||||
remark: bill.remark,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user