Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/samunro/breeze-client into …
Browse files Browse the repository at this point in the history
…samunro-master
  • Loading branch information
steveschmitt committed Apr 2, 2021
2 parents ef721ce + 9a7f9fb commit 6b1fb55
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/adapter-ajax-httpclient.ts
@@ -1,6 +1,7 @@
import { HttpClient, HttpErrorResponse, HttpEvent, HttpHeaders, HttpRequest, HttpResponse } from "@angular/common/http";
import { AjaxConfig, config, core, HttpResponse as BreezeHttpResponse, BreezeConfig } from "breeze-client";
import { filter, map } from "rxjs/operators";
import { appendQueryStringParameters } from "./adapter-core";

export class AjaxHttpClientAdapter {
static adapterName = 'httpclient';
Expand Down Expand Up @@ -36,13 +37,9 @@ export class AjaxHttpClientAdapter {
throw new Error(this.name + ' does not support JSONP (crossDomain) requests');
}

let url = config.url;
if (!core.isEmpty(config.params)) {
// Hack: Not sure how Angular handles writing 'search' parameters to the url.
// so this approach takes over the url param writing completely.
let delim = (url.indexOf('?') >= 0) ? '&' : '?';
url = url + delim + encodeParams(config.params);
}
let parameters = core.isEmpty(config.params) ? null : encodeParams(config.params);

const url = appendQueryStringParameters(parameters, config.url);

let headers = new HttpHeaders(config.headers || {});
if (!headers.has('Content-Type')) {
Expand Down
17 changes: 17 additions & 0 deletions src/adapter-core.ts
@@ -0,0 +1,17 @@
export function appendQueryStringParameters(parameters: string, url: string){
if(!parameters) return url;

let separator: string;

if(url.endsWith("?")){
separator = "";
}
else if(url.includes("?")){
separator = "&";
}
else{
separator = "?";
}

return url + separator + parameters;
}
5 changes: 3 additions & 2 deletions src/adapter-uri-builder-odata.ts
@@ -1,4 +1,5 @@
import * as breeze from 'breeze-client';
import { appendQueryStringParameters } from "./adapter-core";

export class UriBuilderODataAdapter implements breeze.UriBuilderAdapter {

Expand Down Expand Up @@ -44,8 +45,8 @@ export class UriBuilderODataAdapter implements breeze.UriBuilderAdapter {
}

let qoText = toQueryOptionsString(queryOptions as breeze.QueryOptions);
let sep = entityQuery.resourceName.includes("?") ? "&" : "?";
return entityQuery.resourceName + sep + qoText;

return appendQueryStringParameters(qoText, entityQuery.resourceName);

// private methods to this func.

Expand Down

0 comments on commit 6b1fb55

Please sign in to comment.