From d84239b7d3f006a951ab2c4568b1b10867a22c45 Mon Sep 17 00:00:00 2001 From: Grant Forsythe Date: Sun, 14 Jul 2024 16:29:57 -0400 Subject: [PATCH] refactor: move interfaces into declaration file --- .../bar-horizontal.component.spec.ts | 3 - .../bar-chart/bar-vertical.component.spec.ts | 3 - .../reports-form/dashboard-form.component.ts | 2 - src/app/reports/ui/flag/flag.component.ts | 2 - .../ynab/interfaces/accounts/account.ts | 61 --- .../ynab/interfaces/accounts/accountType.ts | 17 - .../interfaces/budgets/detail/budgetDetail.ts | 22 - .../interfaces/budgets/detail/monthSummary.ts | 34 -- .../budgets/summary/budgetSummary.ts | 26 - .../budgets/summary/currencyFormat.ts | 10 - .../interfaces/budgets/summary/dateFormat.ts | 3 - .../ynab/interfaces/categories/category.ts | 79 ---- .../interfaces/categories/categoryGroup.ts | 15 - .../services/ynab/interfaces/payees/payee.ts | 12 - .../ynab/interfaces/payees/payeeLocation.ts | 11 - .../ynab/interfaces/transactions/flagColor.ts | 1 - .../transactions/scheduledSubTransaction.ts | 19 - .../scheduledTransationSummary.ts | 45 -- .../interfaces/transactions/subTransaction.ts | 25 - .../interfaces/transactions/transaction.ts | 9 - .../transactions/transactionSummary.ts | 65 --- .../services/ynab/interfaces/ynabError.ts | 5 - src/app/shared/services/ynab/ynab.d.ts | 447 ++++++++++++++++++ .../shared/services/ynab/ynab.service.spec.ts | 7 - src/app/shared/services/ynab/ynab.service.ts | 7 - src/app/shared/utils/mocks.ts | 6 - src/app/state/actions/budget-cards.actions.ts | 2 - src/app/state/actions/report.actions.ts | 4 - src/app/state/app.state.ts | 5 - src/app/state/effects/budget-cards.effects.ts | 1 - 30 files changed, 447 insertions(+), 501 deletions(-) delete mode 100644 src/app/shared/services/ynab/interfaces/accounts/account.ts delete mode 100644 src/app/shared/services/ynab/interfaces/accounts/accountType.ts delete mode 100644 src/app/shared/services/ynab/interfaces/budgets/detail/budgetDetail.ts delete mode 100644 src/app/shared/services/ynab/interfaces/budgets/detail/monthSummary.ts delete mode 100644 src/app/shared/services/ynab/interfaces/budgets/summary/budgetSummary.ts delete mode 100644 src/app/shared/services/ynab/interfaces/budgets/summary/currencyFormat.ts delete mode 100644 src/app/shared/services/ynab/interfaces/budgets/summary/dateFormat.ts delete mode 100644 src/app/shared/services/ynab/interfaces/categories/category.ts delete mode 100644 src/app/shared/services/ynab/interfaces/categories/categoryGroup.ts delete mode 100644 src/app/shared/services/ynab/interfaces/payees/payee.ts delete mode 100644 src/app/shared/services/ynab/interfaces/payees/payeeLocation.ts delete mode 100644 src/app/shared/services/ynab/interfaces/transactions/flagColor.ts delete mode 100644 src/app/shared/services/ynab/interfaces/transactions/scheduledSubTransaction.ts delete mode 100644 src/app/shared/services/ynab/interfaces/transactions/scheduledTransationSummary.ts delete mode 100644 src/app/shared/services/ynab/interfaces/transactions/subTransaction.ts delete mode 100644 src/app/shared/services/ynab/interfaces/transactions/transaction.ts delete mode 100644 src/app/shared/services/ynab/interfaces/transactions/transactionSummary.ts delete mode 100644 src/app/shared/services/ynab/interfaces/ynabError.ts create mode 100644 src/app/shared/services/ynab/ynab.d.ts diff --git a/src/app/reports/feature/dashboard/bar-chart/bar-horizontal.component.spec.ts b/src/app/reports/feature/dashboard/bar-chart/bar-horizontal.component.spec.ts index 1ee8d1e..d88f92b 100644 --- a/src/app/reports/feature/dashboard/bar-chart/bar-horizontal.component.spec.ts +++ b/src/app/reports/feature/dashboard/bar-chart/bar-horizontal.component.spec.ts @@ -5,9 +5,6 @@ import { MockStore, provideMockStore } from '@ngrx/store/testing'; import { NgxChartsModule } from '@swimlane/ngx-charts'; -import { Account } from '../../../../shared/services/ynab/interfaces/accounts/account'; -import { CategoryGroup } from '../../../../shared/services/ynab/interfaces/categories/categoryGroup'; -import { Transaction } from '../../../../shared/services/ynab/interfaces/transactions/transaction'; import { selectSortedResults } from '../../../../state/selectors/report.selectors'; import { ChartsBarHorizontalComponent } from './bar-horizontal.component'; diff --git a/src/app/reports/feature/dashboard/bar-chart/bar-vertical.component.spec.ts b/src/app/reports/feature/dashboard/bar-chart/bar-vertical.component.spec.ts index a66c671..6936347 100644 --- a/src/app/reports/feature/dashboard/bar-chart/bar-vertical.component.spec.ts +++ b/src/app/reports/feature/dashboard/bar-chart/bar-vertical.component.spec.ts @@ -5,9 +5,6 @@ import { MockStore, provideMockStore } from '@ngrx/store/testing'; import { NgxChartsModule } from '@swimlane/ngx-charts'; -import { Account } from '../../../../shared/services/ynab/interfaces/accounts/account'; -import { CategoryGroup } from '../../../../shared/services/ynab/interfaces/categories/categoryGroup'; -import { Transaction } from '../../../../shared/services/ynab/interfaces/transactions/transaction'; import { selectSortedResults } from '../../../../state/selectors/report.selectors'; import { ChartsBarVerticalComponent } from './bar-vertical.component'; diff --git a/src/app/reports/feature/dashboard/reports-form/dashboard-form.component.ts b/src/app/reports/feature/dashboard/reports-form/dashboard-form.component.ts index e954c49..c25757e 100644 --- a/src/app/reports/feature/dashboard/reports-form/dashboard-form.component.ts +++ b/src/app/reports/feature/dashboard/reports-form/dashboard-form.component.ts @@ -10,8 +10,6 @@ import { Store } from '@ngrx/store'; import { Observable, Subject, combineLatest, startWith, takeUntil } from 'rxjs'; -import { Account } from '../../../../shared/services/ynab/interfaces/accounts/account'; -import { Category } from '../../../../shared/services/ynab/interfaces/categories/category'; import { formActions } from '../../../../state/actions/dashboard-form.actions'; import { FormState } from '../../../../state/app.state'; import { diff --git a/src/app/reports/ui/flag/flag.component.ts b/src/app/reports/ui/flag/flag.component.ts index e3edd2c..9964464 100644 --- a/src/app/reports/ui/flag/flag.component.ts +++ b/src/app/reports/ui/flag/flag.component.ts @@ -1,7 +1,5 @@ import { Component, Input } from '@angular/core'; -import { FlagColor } from '../../../shared/services/ynab/interfaces/transactions/flagColor'; - @Component({ selector: 'app-charts-bar-vertical', standalone: true, diff --git a/src/app/shared/services/ynab/interfaces/accounts/account.ts b/src/app/shared/services/ynab/interfaces/accounts/account.ts deleted file mode 100644 index 4c11799..0000000 --- a/src/app/shared/services/ynab/interfaces/accounts/account.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { AccountType } from './accountType'; - -export interface Account { - id: string; - name: string; - type: AccountType; - /** - * Whether this account is on budget or not - */ - on_budget: boolean; - /** - * Whether this account is closed or not - */ - closed: boolean; - note?: string; - /** - * The current balance of the account in milliunits format - */ - balance: number; - /** - * The current cleared balance of the account in milliunits format - */ - cleared_balance: number; - /** - * The current uncleared balance of the account in milliunits format - */ - uncleared_balance: number; - /** - * The payee id which should be used when transferring to this account - */ - transfer_payee_id: string; - /** - * Whether or not the account is linked to a financial institution for automatic transaction import. - */ - direct_import_linked?: boolean; - /** - * If an account linked to a financial institution (direct_import_linked=true) and the linked connection is not in a healthy state, this will be true. - */ - direct_import_in_error?: boolean; - /** - * A date/time specifying when the account was last reconciled. - */ - last_reconciled_at?: string; - /** - * The original debt/loan account balance, specified in milliunits format. - */ - debt_original_balance?: number; - debt_interest_rates?: { - [key: string]: number | null; - }; - debt_minimum_payments?: { - [key: string]: number | null; - }; - debt_escrow_amounts?: { - [key: string]: number | null; - }; - /** - * Whether or not the account has been deleted. Deleted accounts will only be included in delta requests. - */ - deleted: boolean; -} diff --git a/src/app/shared/services/ynab/interfaces/accounts/accountType.ts b/src/app/shared/services/ynab/interfaces/accounts/accountType.ts deleted file mode 100644 index 7aeaf7e..0000000 --- a/src/app/shared/services/ynab/interfaces/accounts/accountType.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * The type of account - */ -export type AccountType = - | 'checking' - | 'savings' - | 'cash' - | 'creditCard' - | 'lineOfCredit' - | 'otherAsset' - | 'otherLiability' - | 'mortgage' - | 'autoLoan' - | 'studentLoan' - | 'personalLoan' - | 'medicalDebt' - | 'otherDebt'; diff --git a/src/app/shared/services/ynab/interfaces/budgets/detail/budgetDetail.ts b/src/app/shared/services/ynab/interfaces/budgets/detail/budgetDetail.ts deleted file mode 100644 index fcf370f..0000000 --- a/src/app/shared/services/ynab/interfaces/budgets/detail/budgetDetail.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Category } from '../../categories/category'; -import { CategoryGroup } from '../../categories/categoryGroup'; -import { Payee } from '../../payees/payee'; -import { PayeeLocation } from '../../payees/payeeLocation'; -import { ScheduledSubTransaction } from '../../transactions/scheduledSubTransaction'; -import { ScheduledTransactionSummary } from '../../transactions/scheduledTransationSummary'; -import { SubTransaction } from '../../transactions/subTransaction'; -import { TransactionSummary } from '../../transactions/transactionSummary'; -import { BudgetSummary } from '../summary/budgetSummary'; -import { MonthSummary } from './monthSummary'; - -export interface BudgetDetail extends BudgetSummary { - payees?: Payee[]; - payeeLocations?: PayeeLocation[]; - categoryGroups?: Omit; - categories?: Category[]; - months?: MonthSummary[]; - transactions?: TransactionSummary[]; - subtransactions?: SubTransaction[]; - scheduledTransactions?: ScheduledTransactionSummary[]; - scheduledSubTransactions?: ScheduledSubTransaction[]; -} diff --git a/src/app/shared/services/ynab/interfaces/budgets/detail/monthSummary.ts b/src/app/shared/services/ynab/interfaces/budgets/detail/monthSummary.ts deleted file mode 100644 index 22fd287..0000000 --- a/src/app/shared/services/ynab/interfaces/budgets/detail/monthSummary.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Category } from '../../categories/category'; - -export interface MonthSummary { - month: string; - note?: string; - /** - * The total amount of transactions categorized to 'Inflow: Ready to Assign' in the month - */ - income: number; - /** - * The total amount budgeted in the month - */ - budgeted: number; - /** - * The total amount of transactions in the month, excluding those categorized to 'Inflow: Ready to Assign' - */ - activity: number; - /** - * The available amount for 'Ready to Assign' - */ - to_be_budgeted: number; - /** - * The Age of Money as of the month - */ - age_of_money?: number; - /** - * Whether or not the month has been deleted. Deleted months will only be included in delta requests. - */ - deleted: boolean; - /** - * The budget month categories. Amounts (budgeted, activity, balance, etc.) are specific to the {month} parameter specified. - */ - categories: Category[]; -} diff --git a/src/app/shared/services/ynab/interfaces/budgets/summary/budgetSummary.ts b/src/app/shared/services/ynab/interfaces/budgets/summary/budgetSummary.ts deleted file mode 100644 index ff5bb78..0000000 --- a/src/app/shared/services/ynab/interfaces/budgets/summary/budgetSummary.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Account } from '../../accounts/account'; -import { CurrencyFormat } from './currencyFormat'; -import { DateFormat } from './dateFormat'; - -export interface BudgetSummary { - id: string; - name: string; - /** - * The last time any changes were made to the budget from either a web or mobile client - */ - last_modified_on?: string; - /** - * The earliest budget month - */ - first_month?: string; - /** - * The latest budget month - */ - last_month?: string; - date_format?: DateFormat; - currency_format?: CurrencyFormat; - /** - * The budget accounts (only included if `include_accounts=true` specified as query parameter) - */ - accounts?: Account[]; -} diff --git a/src/app/shared/services/ynab/interfaces/budgets/summary/currencyFormat.ts b/src/app/shared/services/ynab/interfaces/budgets/summary/currencyFormat.ts deleted file mode 100644 index 544ec01..0000000 --- a/src/app/shared/services/ynab/interfaces/budgets/summary/currencyFormat.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface CurrencyFormat { - iso_code: string; - example_format: string; - decimal_digits: number; - decimal_separator: string; - symbol_first: boolean; - group_separator: string; - currency_symbol: string; - display_symbol: boolean; -} diff --git a/src/app/shared/services/ynab/interfaces/budgets/summary/dateFormat.ts b/src/app/shared/services/ynab/interfaces/budgets/summary/dateFormat.ts deleted file mode 100644 index 06aa290..0000000 --- a/src/app/shared/services/ynab/interfaces/budgets/summary/dateFormat.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface DateFormat { - format: string; -} diff --git a/src/app/shared/services/ynab/interfaces/categories/category.ts b/src/app/shared/services/ynab/interfaces/categories/category.ts deleted file mode 100644 index b940ec2..0000000 --- a/src/app/shared/services/ynab/interfaces/categories/category.ts +++ /dev/null @@ -1,79 +0,0 @@ -export interface Category { - id: string; - category_group_id: string; - category_group_name?: string; - name: string; - /** - * Whether or not the category is hidden - */ - hidden: boolean; - /** - * DEPRECATED: No longer used. Value will always be null. - */ - original_category_group_id?: string; - note?: string; - /** - * Budgeted amount in milliunits format - */ - budgeted: number; - /** - * Activity amount in milliunits format - */ - activity: number; - /** - * Balance in milliunits format - */ - balance: number; - /** - * The type of goal, if the category has a goal (TB='Target Category Balance', TBD='Target Category Balance by Date', MF='Monthly Funding', NEED='Plan Your Spending') - */ - goal_type?: 'TB' | 'TBD' | 'MF' | 'NEED' | 'DEBT' | 'null'; - /** - * A day offset modifier for the goal's due date. When goal_cadence is 2 (Weekly), this value specifies which day of the week the goal is due (0 = Sunday, 6 = Saturday). Otherwise, this value specifies which day of the month the goal is due (1 = 1st, 31 = 31st, null = Last day of Month). - */ - goal_day?: number; - /** - * The goal cadence. Value in range 0-14. There are two subsets of these values which behave differently. For values 0, 1, 2, and 13, the goal's due date repeats every goal_cadence * goal_cadence_frequency, where 0 = None, 1 = Monthly, 2 = Weekly, and 13 = Yearly. For example, goal_cadence 1 with goal_cadence_frequency 2 means the goal is due every other month. For values 3-12 and 14, goal_cadence_frequency is ignored and the goal's due date repeats every goal_cadence, where 3 = Every 2 Months, 4 = Every 3 Months, ..., 12 = Every 11 Months, and 14 = Every 2 Years. - */ - goal_cadence?: number; - /** - * The goal cadence frequency. When goal_cadence is 0, 1, 2, or 13, a goal's due date repeats every goal_cadence * goal_cadence_frequency. For example, goal_cadence 1 with goal_cadence_frequency 2 means the goal is due every other month. When goal_cadence is 3-12 or 14, goal_cadence_frequency is ignored. - */ - goal_cadence_frequency?: number; - /** - * The month a goal was created - */ - goal_creation_month?: string; - /** - * The goal target amount in milliunits - */ - goal_target?: number; - /** - * The original target month for the goal to be completed. Only some goal types specify this date. - */ - goal_target_month?: string; - /** - * The percentage completion of the goal - */ - goal_percentage_complete?: number; - /** - * The number of months, including the current month, left in the current goal period. - */ - goal_months_to_budget?: number; - /** - * The amount of funding still needed in the current month to stay on track towards completing the goal within the current goal period. This amount will generally correspond to the 'Underfunded' amount in the web and mobile clients except when viewing a category with a Needed for Spending Goal in a future month. The web and mobile clients will ignore any funding from a prior goal period when viewing category with a Needed for Spending Goal in a future month. - */ - goal_under_funded?: number; - /** - * The total amount funded towards the goal within the current goal period. - */ - goal_overall_funded?: number; - /** - * The amount of funding still needed to complete the goal within the current goal period. - */ - goal_overall_left?: number; - /** - * Whether or not the category has been deleted. Deleted categories will only be included in delta requests. - */ - deleted: boolean; -} diff --git a/src/app/shared/services/ynab/interfaces/categories/categoryGroup.ts b/src/app/shared/services/ynab/interfaces/categories/categoryGroup.ts deleted file mode 100644 index f5811b8..0000000 --- a/src/app/shared/services/ynab/interfaces/categories/categoryGroup.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Category } from './category'; - -export interface CategoryGroup { - id: string; - name: string; - /** - * Whether or not the category group is hidden - */ - hidden: boolean; - /** - * Whether or not the category group has been deleted. Deleted category groups will only be included in delta requests. - */ - deleted: boolean; - categories?: Category[]; -} diff --git a/src/app/shared/services/ynab/interfaces/payees/payee.ts b/src/app/shared/services/ynab/interfaces/payees/payee.ts deleted file mode 100644 index 466c740..0000000 --- a/src/app/shared/services/ynab/interfaces/payees/payee.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface Payee { - id: string; - name: string; - /** - * If a transfer payee, the 'account_id' to which this payee transfer to - */ - transfer_account_id?: string; - /** - * Whether or not the payee has been deleted. Deleted payees will only be included in delta requests. - */ - deleted: boolean; -} diff --git a/src/app/shared/services/ynab/interfaces/payees/payeeLocation.ts b/src/app/shared/services/ynab/interfaces/payees/payeeLocation.ts deleted file mode 100644 index 1aa6608..0000000 --- a/src/app/shared/services/ynab/interfaces/payees/payeeLocation.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface PayeeLocation { - id: string; - payeeId: string; - latitude: string; - longitude: string; - /** - * - * Whether or not the payee location has been deleted. Deleted payee locations will only be included in delta requests. - */ - deleted: boolean; -} diff --git a/src/app/shared/services/ynab/interfaces/transactions/flagColor.ts b/src/app/shared/services/ynab/interfaces/transactions/flagColor.ts deleted file mode 100644 index 5813026..0000000 --- a/src/app/shared/services/ynab/interfaces/transactions/flagColor.ts +++ /dev/null @@ -1 +0,0 @@ -export type FlagColor = 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'null'; diff --git a/src/app/shared/services/ynab/interfaces/transactions/scheduledSubTransaction.ts b/src/app/shared/services/ynab/interfaces/transactions/scheduledSubTransaction.ts deleted file mode 100644 index b28ca76..0000000 --- a/src/app/shared/services/ynab/interfaces/transactions/scheduledSubTransaction.ts +++ /dev/null @@ -1,19 +0,0 @@ -export interface ScheduledSubTransaction { - id: string; - scheduled_transaction_id: string; - /** - * The scheduled subtransaction amount in milliunits format - */ - amount: number; - memo?: string; - payee_id?: string; - category_id?: string; - /** - * If a transfer, the account_id which the scheduled subtransaction transfers to - */ - transfer_account_id?: string; - /** - * Whether or not the scheduled subtransaction has been deleted. Deleted scheduled subtransactions will only be included in delta requests. - */ - deleted: boolean; -} diff --git a/src/app/shared/services/ynab/interfaces/transactions/scheduledTransationSummary.ts b/src/app/shared/services/ynab/interfaces/transactions/scheduledTransationSummary.ts deleted file mode 100644 index a91a73d..0000000 --- a/src/app/shared/services/ynab/interfaces/transactions/scheduledTransationSummary.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { FlagColor } from './flagColor'; - -export interface ScheduledTransactionSummary { - id: string; - /** - * The first date for which the Scheduled Transaction was scheduled. - */ - date_first: string; - /** - * The next date for which the Scheduled Transaction is scheduled. - */ - date_next: string; - frequency: - | 'never' - | 'daily' - | 'weekly' - | 'everyOtherWeek' - | 'twiceAMonth' - | 'every4Weeks' - | 'monthly' - | 'everyOtherMonth' - | 'every3Months' - | 'every4Months' - | 'twiceAYear' - | 'yearly' - | 'everyOtherYear'; - /** - * The scheduled transaction amount in milliunits format - */ - amount: number; - memo?: string; - flag_color?: FlagColor; - flag_name?: string; - account_id: string; - payee_id?: string; - category_id?: string; - /** - * If a transfer, the account_id which the scheduled transaction transfers to - */ - transfer_account_id?: string; - /** - * Whether or not the scheduled transaction has been deleted. Deleted scheduled transactions will only be included in delta requests. - */ - deleted: boolean; -} diff --git a/src/app/shared/services/ynab/interfaces/transactions/subTransaction.ts b/src/app/shared/services/ynab/interfaces/transactions/subTransaction.ts deleted file mode 100644 index c767a39..0000000 --- a/src/app/shared/services/ynab/interfaces/transactions/subTransaction.ts +++ /dev/null @@ -1,25 +0,0 @@ -export interface SubTransaction { - id: string; - transaction_id: string; - /** - * The subtransaction amount in milliunits format - */ - amount: number; - memo?: string; - payee_id?: string; - payee_name?: string; - category_id?: string; - category_name?: string; - /** - * If a transfer, the account_id which the subtransaction transfers to - */ - transfer_account_id?: string; - /** - * If a transfer, the id of transaction on the other side of the transfer - */ - transfer_transaction_id?: string; - /** - * Whether or not the subtransaction has been deleted. Deleted subtransactions will only be included in delta requests. - */ - deleted: boolean; -} diff --git a/src/app/shared/services/ynab/interfaces/transactions/transaction.ts b/src/app/shared/services/ynab/interfaces/transactions/transaction.ts deleted file mode 100644 index de1cee5..0000000 --- a/src/app/shared/services/ynab/interfaces/transactions/transaction.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { SubTransaction } from './subTransaction'; -import { TransactionSummary } from './transactionSummary'; - -export interface Transaction extends TransactionSummary { - account_name: string; - payee_name?: string; - category_name?: string; - subtransactions?: SubTransaction[]; -} diff --git a/src/app/shared/services/ynab/interfaces/transactions/transactionSummary.ts b/src/app/shared/services/ynab/interfaces/transactions/transactionSummary.ts deleted file mode 100644 index d5fb995..0000000 --- a/src/app/shared/services/ynab/interfaces/transactions/transactionSummary.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { FlagColor } from './flagColor'; - -export interface TransactionSummary { - id: string; - /** - * The transaction date in ISO format (e.g. 2016-12-01) - */ - date: string; - /** - * The transaction amount in milliunits format - */ - amount: number; - memo?: string; - cleared: 'cleared' | 'uncleared' | 'reconciled'; - /** - * Whether or not the transaction is approved - */ - approved: boolean; - flag_color?: FlagColor; - flag_name?: string; - account_id: string; - payee_id?: string; - category_id?: string; - /** - * If a transfer transaction, the account to which it transfers - */ - transfer_account_id?: string; - /** - * If a transfer transaction, the id of transaction on the other side of the transfer - */ - transfer_transaction_id?: string; - /** - * If transaction is matched, the id of the matched transaction - */ - matched_transaction_id?: string; - /** - * If the transaction was imported, this field is a unique (by account) import identifier. If this transaction was imported through File Based Import or Direct Import and not through the API, the import_id will have the format: 'YNAB:[milliunit_amount]:[iso_date]:[occurrence]'. For example, a transaction dated 2015-12-30 in the amount of -$294.23 USD would have an import_id of 'YNAB:-294230:2015-12-30:1'. If a second transaction on the same account was imported and had the same date and same amount, its import_id would be 'YNAB:-294230:2015-12-30:2'. - */ - import_id?: string; - /** - * If the transaction was imported, the payee name that was used when importing and before applying any payee rename rules - */ - import_payee_name?: string; - /** - * If the transaction was imported, the original payee name as it appeared on the statement - */ - import_payee_name_original?: string; - /** - * If the transaction is a debt/loan account transaction, the type of transaction - */ - debt_transaction_type?: - | 'payment' - | 'refund' - | 'fee' - | 'interest' - | 'escrow' - | 'balanceAdjustment' - | 'credit' - | 'charge' - | 'null'; - /** - * Whether or not the transaction has been deleted. Deleted transactions will only be included in delta requests. - */ - deleted: boolean; -} diff --git a/src/app/shared/services/ynab/interfaces/ynabError.ts b/src/app/shared/services/ynab/interfaces/ynabError.ts deleted file mode 100644 index 7233a06..0000000 --- a/src/app/shared/services/ynab/interfaces/ynabError.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface YnabError { - id: string; - name: string; - detail: string; -} diff --git a/src/app/shared/services/ynab/ynab.d.ts b/src/app/shared/services/ynab/ynab.d.ts new file mode 100644 index 0000000..0996f2a --- /dev/null +++ b/src/app/shared/services/ynab/ynab.d.ts @@ -0,0 +1,447 @@ +interface Account { + id: string; + name: string; + type: AccountType; + /** + * Whether this account is on budget or not + */ + on_budget: boolean; + /** + * Whether this account is closed or not + */ + closed: boolean; + note?: string; + /** + * The current balance of the account in milliunits format + */ + balance: number; + /** + * The current cleared balance of the account in milliunits format + */ + cleared_balance: number; + /** + * The current uncleared balance of the account in milliunits format + */ + uncleared_balance: number; + /** + * The payee id which should be used when transferring to this account + */ + transfer_payee_id: string; + /** + * Whether or not the account is linked to a financial institution for automatic transaction import. + */ + direct_import_linked?: boolean; + /** + * If an account linked to a financial institution (direct_import_linked=true) and the linked connection is not in a healthy state, this will be true. + */ + direct_import_in_error?: boolean; + /** + * A date/time specifying when the account was last reconciled. + */ + last_reconciled_at?: string; + /** + * The original debt/loan account balance, specified in milliunits format. + */ + debt_original_balance?: number; + debt_interest_rates?: { + [key: string]: number | null; + }; + debt_minimum_payments?: { + [key: string]: number | null; + }; + debt_escrow_amounts?: { + [key: string]: number | null; + }; + /** + * Whether or not the account has been deleted. Deleted accounts will only be included in delta requests. + */ + deleted: boolean; +} + +/** + * The type of account + */ +type AccountType = + | 'checking' + | 'savings' + | 'cash' + | 'creditCard' + | 'lineOfCredit' + | 'otherAsset' + | 'otherLiability' + | 'mortgage' + | 'autoLoan' + | 'studentLoan' + | 'personalLoan' + | 'medicalDebt' + | 'otherDebt'; + +interface Payee { + id: string; + name: string; + /** + * If a transfer payee, the 'account_id' to which this payee transfer to + */ + transfer_account_id?: string; + /** + * Whether or not the payee has been deleted. Deleted payees will only be included in delta requests. + */ + deleted: boolean; +} + +interface PayeeLocation { + id: string; + payeeId: string; + latitude: string; + longitude: string; + /** + * + * Whether or not the payee location has been deleted. Deleted payee locations will only be included in delta requests. + */ + deleted: boolean; +} + +interface CurrencyFormat { + iso_code: string; + example_format: string; + decimal_digits: number; + decimal_separator: string; + symbol_first: boolean; + group_separator: string; + currency_symbol: string; + display_symbol: boolean; +} + +interface DateFormat { + format: string; +} + +interface BudgetSummary { + id: string; + name: string; + /** + * The last time any changes were made to the budget from either a web or mobile client + */ + last_modified_on?: string; + /** + * The earliest budget month + */ + first_month?: string; + /** + * The latest budget month + */ + last_month?: string; + date_format?: DateFormat; + currency_format?: CurrencyFormat; + /** + * The budget accounts (only included if `include_accounts=true` specified as query parameter) + */ + accounts?: Account[]; +} + +interface MonthSummary { + month: string; + note?: string; + /** + * The total amount of transactions categorized to 'Inflow: Ready to Assign' in the month + */ + income: number; + /** + * The total amount budgeted in the month + */ + budgeted: number; + /** + * The total amount of transactions in the month, excluding those categorized to 'Inflow: Ready to Assign' + */ + activity: number; + /** + * The available amount for 'Ready to Assign' + */ + to_be_budgeted: number; + /** + * The Age of Money as of the month + */ + age_of_money?: number; + /** + * Whether or not the month has been deleted. Deleted months will only be included in delta requests. + */ + deleted: boolean; + /** + * The budget month categories. Amounts (budgeted, activity, balance, etc.) are specific to the {month} parameter specified. + */ + categories: Category[]; +} + +interface BudgetDetail extends BudgetSummary { + payees?: Payee[]; + payeeLocations?: PayeeLocation[]; + categoryGroups?: Omit; + categories?: Category[]; + months?: MonthSummary[]; + transactions?: TransactionSummary[]; + subtransactions?: SubTransaction[]; + scheduledTransactions?: ScheduledTransactionSummary[]; + scheduledSubTransactions?: ScheduledSubTransaction[]; +} + +interface CategoryGroup { + id: string; + name: string; + /** + * Whether or not the category group is hidden + */ + hidden: boolean; + /** + * Whether or not the category group has been deleted. Deleted category groups will only be included in delta requests. + */ + deleted: boolean; + categories?: Category[]; +} + +interface Category { + id: string; + category_group_id: string; + category_group_name?: string; + name: string; + /** + * Whether or not the category is hidden + */ + hidden: boolean; + /** + * DEPRECATED: No longer used. Value will always be null. + */ + original_category_group_id?: string; + note?: string; + /** + * Budgeted amount in milliunits format + */ + budgeted: number; + /** + * Activity amount in milliunits format + */ + activity: number; + /** + * Balance in milliunits format + */ + balance: number; + /** + * The type of goal, if the category has a goal (TB='Target Category Balance', TBD='Target Category Balance by Date', MF='Monthly Funding', NEED='Plan Your Spending') + */ + goal_type?: 'TB' | 'TBD' | 'MF' | 'NEED' | 'DEBT' | 'null'; + /** + * A day offset modifier for the goal's due date. When goal_cadence is 2 (Weekly), this value specifies which day of the week the goal is due (0 = Sunday, 6 = Saturday). Otherwise, this value specifies which day of the month the goal is due (1 = 1st, 31 = 31st, null = Last day of Month). + */ + goal_day?: number; + /** + * The goal cadence. Value in range 0-14. There are two subsets of these values which behave differently. For values 0, 1, 2, and 13, the goal's due date repeats every goal_cadence * goal_cadence_frequency, where 0 = None, 1 = Monthly, 2 = Weekly, and 13 = Yearly. For example, goal_cadence 1 with goal_cadence_frequency 2 means the goal is due every other month. For values 3-12 and 14, goal_cadence_frequency is ignored and the goal's due date repeats every goal_cadence, where 3 = Every 2 Months, 4 = Every 3 Months, ..., 12 = Every 11 Months, and 14 = Every 2 Years. + */ + goal_cadence?: number; + /** + * The goal cadence frequency. When goal_cadence is 0, 1, 2, or 13, a goal's due date repeats every goal_cadence * goal_cadence_frequency. For example, goal_cadence 1 with goal_cadence_frequency 2 means the goal is due every other month. When goal_cadence is 3-12 or 14, goal_cadence_frequency is ignored. + */ + goal_cadence_frequency?: number; + /** + * The month a goal was created + */ + goal_creation_month?: string; + /** + * The goal target amount in milliunits + */ + goal_target?: number; + /** + * The original target month for the goal to be completed. Only some goal types specify this date. + */ + goal_target_month?: string; + /** + * The percentage completion of the goal + */ + goal_percentage_complete?: number; + /** + * The number of months, including the current month, left in the current goal period. + */ + goal_months_to_budget?: number; + /** + * The amount of funding still needed in the current month to stay on track towards completing the goal within the current goal period. This amount will generally correspond to the 'Underfunded' amount in the web and mobile clients except when viewing a category with a Needed for Spending Goal in a future month. The web and mobile clients will ignore any funding from a prior goal period when viewing category with a Needed for Spending Goal in a future month. + */ + goal_under_funded?: number; + /** + * The total amount funded towards the goal within the current goal period. + */ + goal_overall_funded?: number; + /** + * The amount of funding still needed to complete the goal within the current goal period. + */ + goal_overall_left?: number; + /** + * Whether or not the category has been deleted. Deleted categories will only be included in delta requests. + */ + deleted: boolean; +} + +interface ScheduledTransactionSummary { + id: string; + /** + * The first date for which the Scheduled Transaction was scheduled. + */ + date_first: string; + /** + * The next date for which the Scheduled Transaction is scheduled. + */ + date_next: string; + frequency: + | 'never' + | 'daily' + | 'weekly' + | 'everyOtherWeek' + | 'twiceAMonth' + | 'every4Weeks' + | 'monthly' + | 'everyOtherMonth' + | 'every3Months' + | 'every4Months' + | 'twiceAYear' + | 'yearly' + | 'everyOtherYear'; + /** + * The scheduled transaction amount in milliunits format + */ + amount: number; + memo?: string; + flag_color?: FlagColor; + flag_name?: string; + account_id: string; + payee_id?: string; + category_id?: string; + /** + * If a transfer, the account_id which the scheduled transaction transfers to + */ + transfer_account_id?: string; + /** + * Whether or not the scheduled transaction has been deleted. Deleted scheduled transactions will only be included in delta requests. + */ + deleted: boolean; +} + +interface TransactionSummary { + id: string; + /** + * The transaction date in ISO format (e.g. 2016-12-01) + */ + date: string; + /** + * The transaction amount in milliunits format + */ + amount: number; + memo?: string; + cleared: 'cleared' | 'uncleared' | 'reconciled'; + /** + * Whether or not the transaction is approved + */ + approved: boolean; + flag_color?: FlagColor; + flag_name?: string; + account_id: string; + payee_id?: string; + category_id?: string; + /** + * If a transfer transaction, the account to which it transfers + */ + transfer_account_id?: string; + /** + * If a transfer transaction, the id of transaction on the other side of the transfer + */ + transfer_transaction_id?: string; + /** + * If transaction is matched, the id of the matched transaction + */ + matched_transaction_id?: string; + /** + * If the transaction was imported, this field is a unique (by account) + */ + import_id?: string; + /** + * If the transaction was imported, the payee name that was used when importing and before applying any payee rename rules + */ + import_payee_name?: string; + /** + * If the transaction was imported, the original payee name as it appeared on the statement + */ + import_payee_name_original?: string; + /** + * If the transaction is a debt/loan account transaction, the type of transaction + */ + debt_transaction_type?: + | 'payment' + | 'refund' + | 'fee' + | 'interest' + | 'escrow' + | 'balanceAdjustment' + | 'credit' + | 'charge' + | 'null'; + /** + * Whether or not the transaction has been deleted. Deleted transactions will only be included in delta requests. + */ + deleted: boolean; +} + +type FlagColor = 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'null'; +interface SubTransaction { + id: string; + transaction_id: string; + /** + * The subtransaction amount in milliunits format + */ + amount: number; + memo?: string; + payee_id?: string; + payee_name?: string; + category_id?: string; + category_name?: string; + /** + * If a transfer, the account_id which the subtransaction transfers to + */ + transfer_account_id?: string; + /** + * If a transfer, the id of transaction on the other side of the transfer + */ + transfer_transaction_id?: string; + /** + * Whether or not the subtransaction has been deleted. Deleted subtransactions will only be included in delta requests. + */ + deleted: boolean; +} + +interface ScheduledSubTransaction { + id: string; + scheduled_transaction_id: string; + /** + * The scheduled subtransaction amount in milliunits format + */ + amount: number; + memo?: string; + payee_id?: string; + category_id?: string; + /** + * If a transfer, the account_id which the scheduled subtransaction transfers to + */ + transfer_account_id?: string; + /** + * Whether or not the scheduled subtransaction has been deleted. Deleted scheduled subtransactions will only be included in delta requests. + */ + deleted: boolean; +} + +interface Transaction extends TransactionSummary { + account_name: string; + payee_name?: string; + category_name?: string; + subtransactions?: SubTransaction[]; +} + +interface YnabError { + id: string; + name: string; + detail: string; +} diff --git a/src/app/shared/services/ynab/ynab.service.spec.ts b/src/app/shared/services/ynab/ynab.service.spec.ts index 1bf5b07..d01f6f1 100644 --- a/src/app/shared/services/ynab/ynab.service.spec.ts +++ b/src/app/shared/services/ynab/ynab.service.spec.ts @@ -2,13 +2,6 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/ import { TestBed, waitForAsync } from '@angular/core/testing'; import { mockBudgets, mockCategoryGroups, mockId, mockPayees } from '../../utils/mocks'; -import { Account } from './interfaces/accounts/account'; -import { BudgetDetail } from './interfaces/budgets/detail/budgetDetail'; -import { BudgetSummary } from './interfaces/budgets/summary/budgetSummary'; -import { CategoryGroup } from './interfaces/categories/categoryGroup'; -import { Payee } from './interfaces/payees/payee'; -import { Transaction } from './interfaces/transactions/transaction'; -import { YnabError } from './interfaces/ynabError'; import { YnabService } from './ynab.service'; // TODO: Refactor out diff --git a/src/app/shared/services/ynab/ynab.service.ts b/src/app/shared/services/ynab/ynab.service.ts index c17bf75..6c9ad60 100644 --- a/src/app/shared/services/ynab/ynab.service.ts +++ b/src/app/shared/services/ynab/ynab.service.ts @@ -3,13 +3,6 @@ import { Injectable, inject } from '@angular/core'; import { Observable, catchError, map, shareReplay, throwError } from 'rxjs'; -import { Account } from './interfaces/accounts/account'; -import { BudgetDetail } from './interfaces/budgets/detail/budgetDetail'; -import { BudgetSummary } from './interfaces/budgets/summary/budgetSummary'; -import { CategoryGroup } from './interfaces/categories/categoryGroup'; -import { Payee } from './interfaces/payees/payee'; -import { Transaction } from './interfaces/transactions/transaction'; - const BASE_URL = 'https://api.ynab.com/v1'; // TODO: Refactor in library diff --git a/src/app/shared/utils/mocks.ts b/src/app/shared/utils/mocks.ts index 29687ad..89b1aaf 100644 --- a/src/app/shared/utils/mocks.ts +++ b/src/app/shared/utils/mocks.ts @@ -1,11 +1,5 @@ import { faker } from '@faker-js/faker'; -import { Account } from '../services/ynab/interfaces/accounts/account'; -import { BudgetSummary } from '../services/ynab/interfaces/budgets/summary/budgetSummary'; -import { CategoryGroup } from '../services/ynab/interfaces/categories/categoryGroup'; -import { Payee } from '../services/ynab/interfaces/payees/payee'; -import { Transaction } from '../services/ynab/interfaces/transactions/transaction'; - const from = '2024-01-01T00:00:00.000Z'; const to = '2024-12-31T11:59:00.000Z'; diff --git a/src/app/state/actions/budget-cards.actions.ts b/src/app/state/actions/budget-cards.actions.ts index 0bf044a..5fd4527 100644 --- a/src/app/state/actions/budget-cards.actions.ts +++ b/src/app/state/actions/budget-cards.actions.ts @@ -1,7 +1,5 @@ import { createActionGroup, emptyProps, props } from '@ngrx/store'; -import { BudgetSummary } from '../../shared/services/ynab/interfaces/budgets/summary/budgetSummary'; - export const budgetActions = createActionGroup({ source: 'Budget Page', events: { diff --git a/src/app/state/actions/report.actions.ts b/src/app/state/actions/report.actions.ts index 5d7db5a..aec17e5 100644 --- a/src/app/state/actions/report.actions.ts +++ b/src/app/state/actions/report.actions.ts @@ -1,9 +1,5 @@ import { createActionGroup, emptyProps, props } from '@ngrx/store'; -import { Account } from '../../shared/services/ynab/interfaces/accounts/account'; -import { CategoryGroup } from '../../shared/services/ynab/interfaces/categories/categoryGroup'; -import { Transaction } from '../../shared/services/ynab/interfaces/transactions/transaction'; - export const reportActions = createActionGroup({ source: 'Dashboard Page', events: { diff --git a/src/app/state/app.state.ts b/src/app/state/app.state.ts index 507c2b7..da250b5 100644 --- a/src/app/state/app.state.ts +++ b/src/app/state/app.state.ts @@ -1,8 +1,3 @@ -import { Account } from '../shared/services/ynab/interfaces/accounts/account'; -import { BudgetSummary } from '../shared/services/ynab/interfaces/budgets/summary/budgetSummary'; -import { CategoryGroup } from '../shared/services/ynab/interfaces/categories/categoryGroup'; -import { Transaction } from '../shared/services/ynab/interfaces/transactions/transaction'; - export interface BudgetState { budgets: BudgetSummary[]; } diff --git a/src/app/state/effects/budget-cards.effects.ts b/src/app/state/effects/budget-cards.effects.ts index f0fccfd..9606ad9 100644 --- a/src/app/state/effects/budget-cards.effects.ts +++ b/src/app/state/effects/budget-cards.effects.ts @@ -6,7 +6,6 @@ import { Store } from '@ngrx/store'; import { of, switchMap, tap } from 'rxjs'; -import { BudgetSummary } from '../../shared/services/ynab/interfaces/budgets/summary/budgetSummary'; import { YnabService } from '../../shared/services/ynab/ynab.service'; import { budgetActions } from '../actions/budget-cards.actions';