From 9c8b3cf0e7105f003d397bedcf10dfa9c9c5c4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Umut=20=C3=96zel?= Date: Thu, 26 Sep 2019 11:59:26 +0300 Subject: [PATCH] fix cascading query parameter bug, closes #18. --- lib/odata-query-provider.ts | 11 ++++++++++- lib/odata-query.ts | 4 ++-- test/service.spec.ts | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/odata-query-provider.ts b/lib/odata-query-provider.ts index 2c4a3ed..9f48fc8 100644 --- a/lib/odata-query-provider.ts +++ b/lib/odata-query-provider.ts @@ -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[]) { diff --git a/lib/odata-query.ts b/lib/odata-query.ts index c612684..9deae70 100644 --- a/lib/odata-query.ts +++ b/lib/odata-query.ts @@ -51,7 +51,7 @@ export class ODataQuery implemen public expand>( nav: K1, prm1?: K2[] | Predicate>, prm2?: Predicate>, ...scopes) : IExpandedODataQuery, TExtra> { - const args = createExpandArgs(nav, prm1, prm2, scopes); + const args = createExpandArgs(nav, prm1, prm2, ...scopes); return this.createExpandedQuery>(new QueryPart(ODataFuncs.expand, args)); } @@ -137,7 +137,7 @@ class ExpandedODataQuery>( nav: K1, prm1?: K2[] | Predicate>, prm2?: Predicate>, ...scopes) : IExpandedODataQuery, TExtra> { - const args = createExpandArgs(nav, prm1, prm2, scopes); + const args = createExpandArgs(nav, prm1, prm2, ...scopes); return this.createExpandedQuery(new QueryPart(ODataFuncs.thenExpand, args)); } } diff --git a/test/service.spec.ts b/test/service.spec.ts index cde522d..da5b7ac 100644 --- a/test/service.spec.ts +++ b/test/service.spec.ts @@ -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;