Return list of categories in alphabetical order
This commit is contained in:
parent
6decda838b
commit
4a3794978c
1 changed files with 6 additions and 5 deletions
|
@ -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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue