023612ce0a
- Updated timestamps and AST hashes for multiple files in the manifest.json. - Added new test file backend/tests/test_expected_income.py. - Added documentation files: перево́д_между_своими.md and 0002-fixes.md. - Introduced pytest.ini to configure pytest settings, including test paths and warning filters.
147 lines
6.7 KiB
TypeScript
147 lines
6.7 KiB
TypeScript
import { apiClient } from './client'
|
|
import type {
|
|
AcceptInvitePayload,
|
|
Account,
|
|
AdjustBalancePayload,
|
|
AdjustBalanceResult,
|
|
BalancesReport,
|
|
BudgetCategory,
|
|
BudgetSummary,
|
|
CashFlowMonth,
|
|
CategorizeBatchPayload,
|
|
CategorizeBatchResult,
|
|
CategoryDefinition,
|
|
CategorySpendItem,
|
|
ConfirmImportPayload,
|
|
CreateAccountPayload,
|
|
CreateCategoryPayload,
|
|
CreateOperationPayload,
|
|
ExportInfo,
|
|
ExpectedIncome,
|
|
ExpectedIncomePayload,
|
|
ImportDetail,
|
|
ImportSummary,
|
|
LoginPayload,
|
|
Operation,
|
|
OperationFilters,
|
|
Page,
|
|
PatchCategoryDefinitionPayload,
|
|
PlanFactReport,
|
|
PasswordResetPayload,
|
|
ResolveHoldPayload,
|
|
SaveRowDecisionPayload,
|
|
SpaceDeletionStatus,
|
|
User,
|
|
} from './types'
|
|
|
|
export const api = {
|
|
auth: {
|
|
me: () => apiClient.get<User>('/auth/me'),
|
|
login: (payload: LoginPayload) => apiClient.post<User>('/auth/login', { json: payload }),
|
|
logout: () => apiClient.post<void>('/auth/logout'),
|
|
acceptInvite: (payload: AcceptInvitePayload) =>
|
|
apiClient.post<User>('/auth/invitations/accept', { json: payload }),
|
|
requestPasswordReset: (email: string) =>
|
|
apiClient.post<{ accepted: boolean }>('/auth/password-reset', { json: { email } }),
|
|
confirmPasswordReset: (payload: PasswordResetPayload) =>
|
|
apiClient.post<User>('/auth/password-reset/confirm', { json: payload }),
|
|
},
|
|
accounts: {
|
|
list: () => apiClient.get<Account[]>('/accounts'),
|
|
create: (payload: CreateAccountPayload) =>
|
|
apiClient.post<Account>('/accounts', { json: payload }),
|
|
archive: (id: string) =>
|
|
apiClient.patch<Account>(`/accounts/${id}`, { json: { status: 'archived' } }),
|
|
adjustBalance: (id: string, payload: AdjustBalancePayload) =>
|
|
apiClient.post<AdjustBalanceResult>(`/accounts/${id}/adjust-balance`, { json: payload }),
|
|
},
|
|
operations: {
|
|
list: (filters: OperationFilters) =>
|
|
apiClient.get<Page<Operation>>('/operations', { query: { ...filters } }),
|
|
create: (payload: CreateOperationPayload) =>
|
|
apiClient.post<Operation>('/operations', { json: payload }),
|
|
void: (id: string, reason: string) =>
|
|
apiClient.post<Operation>(`/operations/${id}/void`, { json: { reason } }),
|
|
categorize: (id: string, categoryId: string) =>
|
|
apiClient.patch<Operation>(`/operations/${id}`, { json: { categoryId } }),
|
|
categorizeBatch: (payload: CategorizeBatchPayload) =>
|
|
apiClient.post<CategorizeBatchResult>('/operations/categorize-batch', { json: payload }),
|
|
savingsTransfer: (id: string) =>
|
|
apiClient.post<Operation>(`/operations/${id}/savings-transfer`),
|
|
savingsTransferRevert: (id: string) =>
|
|
apiClient.post<Operation>(`/operations/${id}/savings-transfer/revert`),
|
|
},
|
|
budget: {
|
|
summary: (month: string) =>
|
|
apiClient.get<BudgetSummary>('/budget/summary', { query: { month } }),
|
|
categories: (month: string) =>
|
|
apiClient.get<BudgetCategory[]>('/budget/categories', { query: { month } }),
|
|
updatePlan: (categoryId: string, month: string, plannedKopecks: number) =>
|
|
apiClient.patch<BudgetCategory>(`/budget/categories/${categoryId}`, {
|
|
json: { month, plannedKopecks },
|
|
}),
|
|
fund: (categoryId: string, month: string, amountKopecks: number) =>
|
|
apiClient.post<BudgetCategory>(`/budget/categories/${categoryId}/fund`, {
|
|
json: { month, amountKopecks },
|
|
}),
|
|
close: (month: string) => apiClient.post<BudgetSummary>('/budget/close', { json: { month } }),
|
|
reopen: (month: string) => apiClient.post<BudgetSummary>('/budget/reopen', { json: { month } }),
|
|
copyPrevious: (month: string) =>
|
|
apiClient.post<BudgetSummary>('/budget/copy-previous', { json: { month } }),
|
|
categoryDefinitions: (includeArchived: boolean) =>
|
|
apiClient.get<CategoryDefinition[]>('/budget/category-definitions', {
|
|
query: { includeArchived },
|
|
}),
|
|
createCategory: (payload: CreateCategoryPayload) =>
|
|
apiClient.post<CategoryDefinition>('/budget/categories', { json: payload }),
|
|
updateCategoryDefinition: (id: string, payload: PatchCategoryDefinitionPayload) =>
|
|
apiClient.patch<CategoryDefinition>(`/budget/category-definitions/${id}`, { json: payload }),
|
|
createExpectedIncome: (month: string, payload: ExpectedIncomePayload) =>
|
|
apiClient.post<ExpectedIncome>(`/budget/${month.replace('-', '/')}/expected-incomes`, { json: payload }),
|
|
updateExpectedIncome: (month: string, id: string, payload: ExpectedIncomePayload) =>
|
|
apiClient.patch<ExpectedIncome>(`/budget/${month.replace('-', '/')}/expected-incomes/${id}`, { json: payload }),
|
|
deleteExpectedIncome: (month: string, id: string) =>
|
|
apiClient.delete<void>(`/budget/${month.replace('-', '/')}/expected-incomes/${id}`),
|
|
},
|
|
imports: {
|
|
list: (month?: string) =>
|
|
apiClient.get<ImportSummary[]>('/imports', { query: { month } }),
|
|
get: (id: string) => apiClient.get<ImportDetail>(`/imports/${id}`),
|
|
upload: (file: File, accountId: string) => {
|
|
const formData = new FormData()
|
|
formData.append('file', file)
|
|
formData.append('accountId', accountId)
|
|
return apiClient.post<ImportSummary>('/imports', { formData })
|
|
},
|
|
saveRowDecision: (id: string, rowId: string, payload: SaveRowDecisionPayload) =>
|
|
apiClient.patch<ImportDetail>(`/imports/${id}/rows/${rowId}`, { json: payload }),
|
|
resolveHold: (id: string, rowId: string, payload: ResolveHoldPayload) =>
|
|
apiClient.post<ImportDetail>(`/imports/${id}/rows/${rowId}/resolve`, { json: payload }),
|
|
confirm: (id: string, payload: ConfirmImportPayload) =>
|
|
apiClient.post<ImportDetail>(`/imports/${id}/confirm`, { json: payload }),
|
|
reparse: (id: string) => apiClient.post<ImportDetail>(`/imports/${id}/reparse`),
|
|
revert: (id: string) => apiClient.post<ImportDetail>(`/imports/${id}/revert`),
|
|
},
|
|
analytics: {
|
|
categorySpend: (from: string, to: string) =>
|
|
apiClient.get<CategorySpendItem[]>('/analytics/category-spend', { query: { from, to } }),
|
|
planFact: (month: string) =>
|
|
apiClient.get<PlanFactReport>('/analytics/plan-fact', { query: { month } }),
|
|
cashFlow: (from: string, to: string) =>
|
|
apiClient.get<CashFlowMonth[]>('/analytics/cash-flow', { query: { from, to } }),
|
|
balances: () => apiClient.get<BalancesReport>('/analytics/balances'),
|
|
},
|
|
exports: {
|
|
request: () => apiClient.post<ExportInfo>('/exports'),
|
|
get: (id: string) => apiClient.get<ExportInfo>(`/exports/${id}`),
|
|
},
|
|
spaces: {
|
|
deletionStatus: () => apiClient.get<SpaceDeletionStatus>('/spaces/current/deletion'),
|
|
requestDeletion: (confirmationPhrase: string) =>
|
|
apiClient.post<SpaceDeletionStatus>('/spaces/current/deletion', {
|
|
json: { confirmationPhrase },
|
|
}),
|
|
cancelDeletion: () => apiClient.delete<SpaceDeletionStatus>('/spaces/current/deletion'),
|
|
},
|
|
}
|