Skip to content

Commit

Permalink
fix(search): fix custom baseUrl not working on search
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyupe committed Mar 12, 2020
1 parent 647e25c commit 486ba2f
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/xivapi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ export class XivapiService {
* @param options Search options, see http://xivapi.com/docs/Search for more details.
*/
public search(options: XivapiSearchOptions): Observable<any> {
let queryParams: HttpParams = this.prepareQueryString(options);
if (options.filters) {
const filterChain: string = options.filters.reduce((chain, filter) => {
const value: string = filter.value instanceof Array ? filter.value.join(';') : filter.value.toString();
return `${chain}${filter.column}${filter.operator}${value},`;
}, '').slice(0, -1);
queryParams = queryParams.set('filters', filterChain);
}
const baseUrl: string = options.staging ? XivapiService.STAGING_API_BASE_URL : XivapiService.API_BASE_URL;
if (options.staging) {
queryParams = queryParams.delete('staging');

if (!options.extraQueryParams) {
options.extraQueryParams = {};
}
options.extraQueryParams.filters = filterChain;
}
return this.doGet<any>(`${baseUrl}/Search`, queryParams);

return this.request<any>('/Search', options);
}

/**
Expand Down Expand Up @@ -261,9 +261,14 @@ export class XivapiService {
if (options === null || options === undefined) {
return queryString;
}
Object.keys(options)
.filter(key => key !== 'extraQueryParams')

const { extraQueryParams, ...rest } = options;
Object.keys(rest)
.forEach(optionKey => {
if (extraQueryParams && Object.prototype.hasOwnProperty.call(extraQueryParams, optionKey)) {
return;
}

// @ts-ignore
const value: any = options[optionKey] as any;
if (value instanceof Array) {
Expand All @@ -272,11 +277,11 @@ export class XivapiService {
queryString = queryString.set(optionKey, value.toString());
}
});
if (options.extraQueryParams !== undefined) {
Object.keys(options.extraQueryParams)
if (extraQueryParams) {
Object.keys(extraQueryParams)
.forEach(key => {
// @ts-ignore
queryString = queryString.set(key, options.extraQueryParams[key].toString());
queryString = queryString.set(key, extraQueryParams[key].toString());
});
}
return queryString;
Expand Down

0 comments on commit 486ba2f

Please sign in to comment.