Skip to content

Commit

Permalink
Added parsing for getItemById request URL
Browse files Browse the repository at this point in the history
  • Loading branch information
yoxigen-zz committed Dec 13, 2017
1 parent 2c62f3e commit cacf2de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/entity/entity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>){
super(config, entityConstructor);
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions lib/repository/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class Repository<T extends EntityModelBase> implements IRepository {
});
}

getItemById(itemId: string | number, options: DataOptions = defaultDataOptions): Observable<T> {
getItemById(itemId: string | number, options: DataOptions = defaultDataOptions, params?:{ [index:string]:any }): Observable<T> {
if (this.entity.values) {

let entityValue: T;
Expand All @@ -327,7 +327,7 @@ export class Repository<T extends EntityModelBase> 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));
}
}
Expand Down

0 comments on commit cacf2de

Please sign in to comment.