Add params option for GET requests to halRequest

pull/4734/head
Alex Dik 8 years ago
parent 3105acaaa6
commit 8cfc8ea8ee
  1. 18
      frontend/app/components/api/api-v3/hal-request/hal-request.service.test.ts
  2. 12
      frontend/app/components/api/api-v3/hal-request/hal-request.service.ts

@ -67,9 +67,10 @@ describe('halRequest service', () => {
describe(`when performing a ${requestMethod} request`, () => {
beforeEach(() => {
method = requestMethod;
data = {foo: 'bar'};
if (method !== 'get') {
data = {foo: 'bar'};
if (method === 'get') {
data = null;
}
callback();
@ -100,6 +101,19 @@ describe('halRequest service', () => {
});
});
describe('when requesting a GET resource with parameters', () => {
const params = {foo: 'bar'};
beforeEach(() => {
promise = halRequest.get('href', params);
});
it('should append the parameters at the end of the requested url', () => {
$httpBackend.expectGET('href?foo=bar').respond(200, {});
$httpBackend.flush();
});
});
describe('when requesting a null href', () => {
beforeEach(() => {
promise = halRequest.request('get', null);

@ -49,10 +49,15 @@ export class HalRequestService {
return this.$q.when(null);
}
const config = {method: method, url: href, data: data};
const config:any = {method: method, url: href, data: data};
const createResource =
response => this.halResourceFactory.createHalResource(response.data);
if (method === 'get') {
delete config.data;
config.params = data;
}
return this.$http(config).then(createResource, createResource);
}
@ -60,10 +65,11 @@ export class HalRequestService {
* Perform a GET request and return a resource promise.
*
* @param href
* @param params
* @returns {ng.IPromise<HalResource>}
*/
public get(href:string):ng.IPromise<HalResource> {
return this.request('get', href);
public get(href:string, params?:any):ng.IPromise<HalResource> {
return this.request('get', href, params);
}
/**

Loading…
Cancel
Save