93 lines
2.2 KiB
TypeScript
93 lines
2.2 KiB
TypeScript
import { ApiClient } from './base'
|
|
import type { Currency } from './data'
|
|
import { type Page, type PageRequest } from './pagination'
|
|
import type { Profile } from './profile'
|
|
|
|
export interface TransactionVendor {
|
|
id: number
|
|
name: string
|
|
description: string
|
|
}
|
|
|
|
export interface TransactionVendorPayload {
|
|
name: string
|
|
description: string
|
|
}
|
|
|
|
export interface Transaction {
|
|
id: number
|
|
timestamp: string
|
|
addedAt: string
|
|
amount: number
|
|
currency: string
|
|
description: string
|
|
vendorId: number | null
|
|
categoryId: number | null
|
|
}
|
|
|
|
export interface TransactionsListItem {
|
|
id: number
|
|
timestamp: string
|
|
addedAt: string
|
|
amount: number
|
|
currency: Currency
|
|
description: string
|
|
vendor: TransactionsListItemVendor | null
|
|
category: TransactionsListItemCategory | null
|
|
creditedAccount: TransactionsListItemAccount | null
|
|
debitedAccount: TransactionsListItemAccount | null
|
|
}
|
|
|
|
export interface TransactionsListItemVendor {
|
|
id: number
|
|
name: string
|
|
}
|
|
|
|
export interface TransactionsListItemCategory {
|
|
id: number
|
|
name: string
|
|
color: string
|
|
}
|
|
|
|
export interface TransactionsListItemAccount {
|
|
id: number
|
|
name: string
|
|
type: string
|
|
numberSuffix: string
|
|
}
|
|
|
|
export class TransactionApiClient extends ApiClient {
|
|
readonly path: string
|
|
|
|
constructor(profile: Profile) {
|
|
super()
|
|
this.path = `/profiles/${profile.name}`
|
|
}
|
|
|
|
async getVendors(): Promise<TransactionVendor[]> {
|
|
return await super.getJson(this.path + '/vendors')
|
|
}
|
|
|
|
async getVendor(id: number): Promise<TransactionVendor> {
|
|
return await super.getJson(this.path + '/vendors/' + id)
|
|
}
|
|
|
|
async createVendor(data: TransactionVendorPayload): Promise<TransactionVendor> {
|
|
return await super.postJson(this.path + '/vendors', data)
|
|
}
|
|
|
|
async updateVendor(id: number, data: TransactionVendorPayload): Promise<TransactionVendor> {
|
|
return await super.putJson(this.path + '/vendors/' + id, data)
|
|
}
|
|
|
|
async deleteVendor(id: number): Promise<void> {
|
|
return await super.delete(this.path + '/vendors/' + id)
|
|
}
|
|
|
|
async getTransactions(
|
|
paginationOptions: PageRequest | undefined = undefined,
|
|
): Promise<Page<TransactionsListItem>> {
|
|
return await super.getJsonPage(this.path + '/transactions', paginationOptions)
|
|
}
|
|
}
|