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 14, 2017
1 parent cacf2de commit 0fab7db
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions bundle/lib/entity/entity.config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export declare class ModelEntity extends EntityConfigBase {
parseDataQuery?: (dataQuery: DataQuery) => {
[index: string]: any;
};
parseItemQuery?: (itemId: string | number, entity?: ModelEntity, config?: ParisConfig) => string;
constructor(config: EntityConfig, entityConstructor: DataEntityConstructor<any>);
}
export interface EntityConfig extends IEntityConfigBase {
Expand All @@ -26,6 +27,7 @@ export interface EntityConfig extends IEntityConfigBase {
parseDataQuery?: (dataQuery: DataQuery) => {
[index: string]: any;
};
parseItemQuery?: (itemId: string | number, entity?: ModelEntity, config?: ParisConfig) => string;
}
export interface ModelEntityCacheConfig {
time?: number;
Expand Down
4 changes: 3 additions & 1 deletion bundle/lib/repository/repository.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export declare class Repository<T extends EntityModelBase> implements IRepositor
private static getEntityItem<U>(repository, data, options?);
private static getValueObjectItem<U>(valueObjectType, data, options, paris, config?);
query(query?: DataQuery, dataOptions?: DataOptions): Observable<DataSet<T>>;
getItemById(itemId: string | number, options?: DataOptions): Observable<T>;
getItemById(itemId: string | number, options?: DataOptions, params?: {
[index: string]: any;
}): Observable<T>;
private setAllItems();
getItemSaveData(item: T): Index;
}
4 changes: 2 additions & 2 deletions bundle/lib/repository/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ var Repository = /** @class */ (function () {
});
});
};
Repository.prototype.getItemById = function (itemId, options) {
Repository.prototype.getItemById = function (itemId, options, params) {
var _this = this;
if (options === void 0) { options = data_options_1.defaultDataOptions; }
if (this.entity.values) {
Expand All @@ -285,7 +285,7 @@ var Repository = /** @class */ (function () {
if (this.entity.loadAll)
return this.setAllItems().map(function () { return _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(function (data) { return _this.createItem(data, options); });
}
};
Expand Down
4 changes: 2 additions & 2 deletions bundle/paris.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ var Repository = /** @class */ (function () {
});
});
};
Repository.prototype.getItemById = function (itemId, options) {
Repository.prototype.getItemById = function (itemId, options, params) {
var _this = this;
if (options === void 0) { options = data_options.defaultDataOptions; }
if (this.entity.values) {
Expand All @@ -804,7 +804,7 @@ var Repository = /** @class */ (function () {
if (this.entity.loadAll)
return this.setAllItems().map(function () { return _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(function (data) { return _this.createItem(data, options); });
}
};
Expand Down

0 comments on commit 0fab7db

Please sign in to comment.