first commit
This commit is contained in:
52
composables/useMoney.ts
Normal file
52
composables/useMoney.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
export type TransactionType = 'income' | 'expense'
|
||||
export type AssetBalanceType = 'cumulative' | 'monthly_reset'
|
||||
|
||||
export interface Asset {
|
||||
id: string
|
||||
name: string
|
||||
balanceType: AssetBalanceType
|
||||
initialBalance: number
|
||||
active: boolean
|
||||
sortOrder: number
|
||||
balance?: number
|
||||
}
|
||||
|
||||
export interface Category {
|
||||
id: string
|
||||
type: TransactionType
|
||||
name: string
|
||||
parentId: string | null
|
||||
sortOrder: number
|
||||
active: boolean
|
||||
parent?: Category | null
|
||||
children?: Category[]
|
||||
}
|
||||
|
||||
export interface Transaction {
|
||||
id: string
|
||||
type: TransactionType
|
||||
occurredAt: string
|
||||
assetId: string
|
||||
categoryId: string
|
||||
amount: number
|
||||
title: string
|
||||
memo: string | null
|
||||
latitude: string | null
|
||||
longitude: string | null
|
||||
asset: Asset
|
||||
category: Category & { parent?: Category | null }
|
||||
}
|
||||
|
||||
export function useMoneyApi() {
|
||||
const refresh = () => refreshNuxtData()
|
||||
|
||||
return {
|
||||
refresh,
|
||||
assets: () => useFetch<Asset[]>('/api/assets'),
|
||||
categories: () => useFetch<Category[]>('/api/categories'),
|
||||
transactions: (month: Ref<string>) =>
|
||||
useFetch<{ summary: { income: number; expense: number; diff: number }; transactions: Transaction[] }>('/api/transactions', {
|
||||
query: { month }
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user