Skip to content

Commit

Permalink
feat: get payees, categories, transactions
Browse files Browse the repository at this point in the history
Add getPayees, getCategories, and getTransactions method to
ynab.service.
  • Loading branch information
grantwforsythe committed Mar 5, 2024
1 parent e571f50 commit 64bc07c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MonthSummary } from './monthSummary';
export interface BudgetDetail extends BudgetSummary {
payees?: Payee[];
payeeLocations?: PayeeLocation[];
categoryGroupss?: CategoryGroup[];
categoryGroupss?: Omit<CategoryGroup[], 'categories'>;
categories?: Category[];
months?: MonthSummary[];
transactions?: TransactionSummary[];
Expand Down
3 changes: 3 additions & 0 deletions src/app/services/ynab/interfaces/categories/categoryGroup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Category } from './category';

export interface CategoryGroup {
id: string;
name: string;
Expand All @@ -9,4 +11,5 @@ export interface CategoryGroup {
* Whether or not the category group has been deleted. Deleted category groups will only be included in delta requests.
*/
deleted: boolean;
categories?: Category[];
}
39 changes: 38 additions & 1 deletion src/app/services/ynab/ynab.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable, catchError, map, throwError } from 'rxjs';
import { BudgetSummary } from './interfaces/budgets/summary/budgetSummary';

import { BudgetDetail } from './interfaces/budgets/detail/budgetDetail';
import { BudgetSummary } from './interfaces/budgets/summary/budgetSummary';
import { PayeeLocation } from './interfaces/payees/payeeLocation';
import { Transaction } from './interfaces/transactions/transaction';
import { CategoryGroup } from './interfaces/categories/categoryGroup';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -44,4 +48,37 @@ export class YnabService {
catchError(this.handleError),
);
}

getCategories(budgetId: string) {
return this.http
.get<{
data: { categories: CategoryGroup[]; server_knowledge: number };
}>(`https://api.ynab/com/v1/budgets/${budgetId}/categories`)
.pipe(
map(({ data }) => data.categories),
catchError(this.handleError),
);
}

getPayees(budgetId: string): Observable<PayeeLocation[]> {
return this.http
.get<{
data: { payees: PayeeLocation[]; server_knowledge: number };
}>(`https://api.ynab.com/v1/budgets/${budgetId}/payees`)
.pipe(
map(({ data }) => data.payees),
catchError(this.handleError),
);
}

getTransactions(budgetId: string): Observable<Transaction[]> {
return this.http
.get<{
data: { transactions: Transaction[]; server_knowledge: number };
}>(`https://api.ynab.com/v1/budgets/${budgetId}/transactions`)
.pipe(
map(({ data }) => data.transactions),
catchError(this.handleError),
);
}
}

0 comments on commit 64bc07c

Please sign in to comment.