Skip to content

Commit

Permalink
fix cascading query parameter bug, closes #18.
Browse files Browse the repository at this point in the history
  • Loading branch information
umutozel committed Sep 26, 2019
1 parent 4b51f08 commit 9c8b3cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
11 changes: 10 additions & 1 deletion lib/odata-query-provider.ts
Expand Up @@ -235,11 +235,20 @@ export class ODataQueryProvider implements IQueryProvider {

public memberToStr(exp: MemberExpression, scopes: any[], parameters: string[]) {
const owner = this.expToStr(exp.owner, scopes, parameters);

if (!owner) {
return exp.name;
}

if (typeof owner === "object") {
return this.valueToStr(owner[exp.name]);
}

if (exp.name === "length") {
return `length(${owner})`;
}

return owner ? `${owner}/${exp.name}` : exp.name;
return `${owner}/${exp.name}`;
}

public funcToStr(exp: FuncExpression, scopes: any[], parameters: string[]) {
Expand Down
4 changes: 2 additions & 2 deletions lib/odata-query.ts
Expand Up @@ -51,7 +51,7 @@ export class ODataQuery<T extends object, TResponse = any, TExtra = {}> implemen
public expand<K1 extends keyof T, K2 extends keyof AU<T[K1]>>(
nav: K1, prm1?: K2[] | Predicate<AU<T[K1]>>, prm2?: Predicate<AU<T[K1]>>, ...scopes)
: IExpandedODataQuery<T, AU<T[K1]>, TExtra> {
const args = createExpandArgs(nav, prm1, prm2, scopes);
const args = createExpandArgs(nav, prm1, prm2, ...scopes);
return this.createExpandedQuery<AU<T[K1]>>(new QueryPart(ODataFuncs.expand, args));
}

Expand Down Expand Up @@ -137,7 +137,7 @@ class ExpandedODataQuery<TEntity extends object, TProperty, TResponse = any, TEx
public thenExpand<K1 extends keyof TProperty, K2 extends keyof AU<TProperty[K1]>>(
nav: K1, prm1?: K2[] | Predicate<AU<TProperty[K1]>>, prm2?: Predicate<AU<TProperty[K1]>>, ...scopes)
: IExpandedODataQuery<TEntity, AU<TProperty[K1]>, TExtra> {
const args = createExpandArgs(nav, prm1, prm2, scopes);
const args = createExpandArgs(nav, prm1, prm2, ...scopes);
return this.createExpandedQuery<any>(new QueryPart(ODataFuncs.thenExpand, args));
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/service.spec.ts
Expand Up @@ -219,11 +219,12 @@ describe("Service tests", () => {
});

it("should handle expand with multi level with repeated calls", () => {
const options = { city: "Gotham" };
const id = 42;
const query = service.companies()
.expand("addresses", ["city"])
.expand("addresses", (a) => a.id > id, { id })
.thenExpand("city", (c) => c.name === "Gotham")
.thenExpand("city", (c) => c.name === options.city, { options })
.thenExpand("country");
expect(query.toArrayAsync()).to.be.fulfilled.and.eventually.be.null;

Expand Down

0 comments on commit 9c8b3cf

Please sign in to comment.