Return list of categories in alphabetical order

This commit is contained in:
William Brawner 2018-09-02 19:45:02 -05:00
parent 6decda838b
commit 4a3794978c

View file

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { of, Observable, from } from 'rxjs'; import { of, Observable, from } from 'rxjs';
import { BudgetDatabase } from './budget-database'; import { BudgetDatabase, ICategory } from './budget-database';
import { TransactionType } from './transaction.type' import { TransactionType } from './transaction.type'
import { Category } from './category' import { Category } from './category'
@ -12,10 +12,11 @@ export class CategoryService {
constructor(private db: BudgetDatabase) { } constructor(private db: BudgetDatabase) { }
getCategories(count?: number): Observable<Category[]> { getCategories(count?: number): Observable<Category[]> {
let collection = this.db.categories.orderBy('name');
if (count) { if (count) {
return from(this.db.categories.toCollection().limit(count).toArray()) return from(collection.limit(count).toArray())
} else { } else {
return from(this.db.categories.toCollection().toArray()) return from(collection.toArray())
} }
} }