adamspe / odata-resource

Node.JS+Express+REST
https://www.npmjs.com/package/odata-resource
12 stars 4 forks source link

filter question #6

Closed alperenboyaci closed 6 years ago

alperenboyaci commented 6 years ago

Hi

can you help me ? I have a 2 questions


part of my data like that { platforms:{"appStore":true, "googlePlay":true, "winStore":false} }

how can get a result from if appStore is true ?

?$filter=contains(platforms,'appStore') ??? true ? ?$filter=in(platforms,'appStore') ??? true ?


part fo my query like that

?$filter=releaseDate le ' 2018.05.17' and endDate gt '2018.05.17'

date part must be use as a dynamic for now/Date() how can I solve it like ?$filter=releaseDate le Date() and endDate gt Date()

is there any way for it ?

thanks

adamspe commented 6 years ago

The first one should just be a simple equality match.

E.g. ?$filter=platforms.appStore eq true

For the later, you'll need to generate and format the date when building the $filter. E.g.

// not emptying out hour, min, sec
const formatDate = (d) => JSON.stringify(d).replace(/"/g,'');
const now = new Date();
const nowFormatted = formDate(now);
filter = `releaseDate le ${nowFormatted} and endDate gt ${nowFormatted}`;

You can see a few basic date filtering examples in test/filter.js in the date-eq|inc|ge-ordered test cases.

alperenboyaci commented 6 years ago

Hi Thanks for your help. I am newbie on odata side with my sql mentality :) There are many differencies.

I need $expand function for using like inner/outer join for me. I see $expand is merge data to upper-level but I need data a kind of treeview may be we calll reverse-expand.

Is there any method/way for making it ? Thanks

picture2

adamspe commented 6 years ago

First, the library is "odata'ish" in nature (I probably should have named it differently). It leverages many of the odata query arguments and the $filter syntax since they're logical and well defined.

I added $expand rather quickly when someone requested it and I'm not too happy with how it functions (at least WRT to mixing it with $select). In this case, If I'm understanding your question right you just want to expand two levels of references?

Every property referenced in $expand has to point to a reference. In this case I think you should just be able to specify the path you want expanded like publishersId.authorsId which should cause the item pointed to by publishersId and the nested reference authorsId within it. Remember that for $expand to work properly you must specify the ref property in your Mongoose schema for those reference properties, otherwise, Mongoose will simply ignore the request to expand the references quietly.

If you need something fancier than that then you may need to override/extend the behavior in the resource implementation.

adamspe commented 6 years ago

Closing since there hasn't been an update to this thread in a while. If you have further questions let me know. Thanks.