53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
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 }
|
|
})
|
|
}
|
|
}
|