Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom HTTP Parameter #349

Open
wants to merge 3 commits into
base: v3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/interfaces/params-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IParamsCollection extends IParams {
storage_ttl?: number;
/** @deprecated since 2.2 */
cachehash?: string; // solution for when we have different resources with a same id
custom_http_params?: Array<string>;
}

export interface IBuildedParamsCollection extends IParams {
Expand All @@ -27,4 +28,5 @@ export interface IBuildedParamsCollection extends IParams {
storage_ttl: number;
/** @deprecated since 2.2 */
cachehash: string; // solution for when we have different resources with a same id
custom_http_params: Array<string>;
}
3 changes: 2 additions & 1 deletion src/services/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class Base {
page: new Page(),
store_cache_method: 'individual',
storage_ttl: 0,
cachehash: ''
cachehash: '',
custom_http_params: []
};

public static newCollection<R extends Resource = Resource>(): DocumentCollection<R> {
Expand Down
5 changes: 5 additions & 0 deletions src/services/path-collection-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ describe('Path Builder', () => {
expect((path_collection_builder as any).get_params.length).toBe(3);
expect((path_collection_builder as any).get_params).toEqual(['filter[status]=test_status', 'page_index=2', 'page_size=10']);
});
it('if custom_http_params params are provided, applyParams method should join the array with "&" and call addParam with the resulting string', () => {
let addParam_parent_spy = spyOn<any>(path_collection_builder, 'addParam');
path_collection_builder.applyParams(testService, { custom_http_params: ['param1', 'param2'] });
expect(addParam_parent_spy).toHaveBeenCalledWith('param1&param2');
});
});
3 changes: 3 additions & 0 deletions src/services/path-collection-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class PathCollectionBuilder extends PathBuilder {
if (params.sort && params.sort.length) {
this.addParam('sort=' + params.sort.join(','));
}
if (params.custom_http_params && params.custom_http_params.length > 0){
this.addParam(params.custom_http_params.join('&'));
}
}

private getPageConfig(): { number: string; size: string } {
Expand Down