import { Observable } from 'rxjs'; import { AuthHttp } from 'angular2-jwt'; import { Response } from '@angular/http'; import { UrlParamBuilderService } from '../service/url-param-builder.service'; import { IErrorHandler } from '../error/error-handler.interface'; import { CardCollection } from './card.collection'; import { CardCollectionConverter } from './card.collection.converter'; import { ApiPathComponent } from '../api-path-component'; export class CardService { public constructor( private authHttp: AuthHttp, private collectionConverter: CardCollectionConverter, private baseUrl: string, private urlParamBuilderService: UrlParamBuilderService, private errorHandler: IErrorHandler ) {} public getMany(filters?: {[key: string]: any}, sort?: string[], page?: number, limit?: number): Observable { const url: string = this.baseUrl + '/' + ApiPathComponent.cards + '?' + this.urlParamBuilderService.build(filters, sort, page, limit) ; return this.authHttp.get(url) .catch((error?: any) => this.errorHandler.handle(error)) .map((res: Response) => this.collectionConverter.toCollection(res.json())); } }