From cacf2debe9082c748f673bcd178a4fce2890bb75 Mon Sep 17 00:00:00 2001 From: Yossi Kolesnicov Date: Wed, 13 Dec 2017 18:54:05 +0200 Subject: [PATCH] Added parsing for getItemById request URL --- lib/entity/entity.config.ts | 4 +++- lib/repository/repository.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/entity/entity.config.ts b/lib/entity/entity.config.ts index 613c20e..6c300fb 100644 --- a/lib/entity/entity.config.ts +++ b/lib/entity/entity.config.ts @@ -12,6 +12,7 @@ export class ModelEntity extends EntityConfigBase{ allItemsEndpoint?:string; allItemsEndpointTrailingSlash?:boolean; parseDataQuery?:(dataQuery:DataQuery) => { [index:string]:any }; + parseItemQuery?:(itemId:string|number, entity?:ModelEntity, config?:ParisConfig) => string; constructor(config:EntityConfig, entityConstructor:DataEntityConstructor){ super(config, entityConstructor); @@ -30,7 +31,8 @@ export interface EntityConfig extends IEntityConfigBase{ allItemsProperty?:string, allItemsEndpoint?:string, allItemsEndpointTrailingSlash?:boolean, - parseDataQuery?:(dataQuery:DataQuery) => { [index:string]:any } + parseDataQuery?:(dataQuery:DataQuery) => { [index:string]:any }, + parseItemQuery?:(itemId:string|number, entity?:ModelEntity, config?:ParisConfig) => string } export interface ModelEntityCacheConfig{ diff --git a/lib/repository/repository.ts b/lib/repository/repository.ts index 5beb3c7..9a11aba 100644 --- a/lib/repository/repository.ts +++ b/lib/repository/repository.ts @@ -307,7 +307,7 @@ export class Repository implements IRepository { }); } - getItemById(itemId: string | number, options: DataOptions = defaultDataOptions): Observable { + getItemById(itemId: string | number, options: DataOptions = defaultDataOptions, params?:{ [index:string]:any }): Observable { if (this.entity.values) { let entityValue: T; @@ -327,7 +327,7 @@ export class Repository implements IRepository { if (this.entity.loadAll) return this.setAllItems().map(() => this._allValuesMap.get(String(itemId))); else { - return this.dataStore.get(`${this.endpointName}/${itemId}`) + return this.dataStore.get(this.entity.parseItemQuery ? this.entity.parseItemQuery(itemId, this.entity, this.config) : `${this.endpointName}/${itemId}`, params && { params: params }, this.baseUrl) .flatMap(data => this.createItem(data, options)); } }