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; }) )