From 4a3794978ca35255ca83b453462b51b7e1f27e50 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sun, 2 Sep 2018 19:45:02 -0500 Subject: [PATCH 1/2] Return list of categories in alphabetical order --- src/app/category.service.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/app/category.service.ts b/src/app/category.service.ts index 4dd9672..acc5d86 100644 --- a/src/app/category.service.ts +++ b/src/app/category.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { of, Observable, from } from 'rxjs'; -import { BudgetDatabase } from './budget-database'; +import { BudgetDatabase, ICategory } from './budget-database'; import { TransactionType } from './transaction.type' import { Category } from './category' @@ -12,10 +12,11 @@ export class CategoryService { constructor(private db: BudgetDatabase) { } getCategories(count?: number): Observable { + let collection = this.db.categories.orderBy('name'); if (count) { - return from(this.db.categories.toCollection().limit(count).toArray()) + return from(collection.limit(count).toArray()) } else { - return from(this.db.categories.toCollection().toArray()) + return from(collection.toArray()) } } @@ -40,13 +41,13 @@ export class CategoryService { getBalance(category: Category): Observable { let sum = 0; return from( - this.db.transactions.filter(transaction => transaction.categoryId === category.id).each(function(transaction) { + this.db.transactions.filter(transaction => transaction.categoryId === category.id).each(function (transaction) { if (transaction.type === TransactionType.INCOME) { sum += transaction.amount } else { sum -= transaction.amount } - }).then(function() { + }).then(function () { return sum; }) ) From 851ef9cfea9cce851b35ecc4cb15c843cf79a208 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sun, 2 Sep 2018 19:47:39 -0500 Subject: [PATCH 2/2] Remove unnecessary import --- src/app/category.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/category.service.ts b/src/app/category.service.ts index acc5d86..e5fff18 100644 --- a/src/app/category.service.ts +++ b/src/app/category.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { of, Observable, from } from 'rxjs'; -import { BudgetDatabase, ICategory } from './budget-database'; +import { BudgetDatabase } from './budget-database'; import { TransactionType } from './transaction.type' import { Category } from './category'