ODataAngularResources icon indicating copy to clipboard operation
ODataAngularResources copied to clipboard

How to filter a collection by datetime?

Open miki-nis opened this issue 7 years ago • 1 comments

I have an endpoint that returns Post objects which have collections of PostComment objects, both of which have property LastModifiedDateTime of type DateTime. I am trying to query this endpoint by either Post/LastModifiedDateTime OR PostComment/LastModifiedDateTime with operator ">" and a specific datetime.

The URL query that accomplishes this looks like: https://localhost:44302/odata/Posts?$expand=PostResources,PostComments&$filter=(LastModifiedDateTime gt 2017-04-21T05:54:15.167Z) or (PostComments/any(c: c/LastModifiedDateTime gt 2017-04-21T05:54:15.167Z))&$orderby=CreatedDateTime desc

I am having trouble writing Predicates that accomplish this in angular code.

var predicates = []; var unreadPost = new $odata.Predicate("LastModifiedDateTime", ">", new $odata.Value(syncService.postSeenDateTime, "DateTimeOffset")); predicates.push(unreadPost);

// how to write predicate for 'any' of the nested LastModifiedDateTime gt than a date here ?

filter = $odata.Predicate.or(predicates);

var posts = context.odata() .expand("PostResources") .expand("PostComments") .filter(predicates ) .orderBy("CreatedDateTime", "desc");

miki-nis avatar Apr 22 '17 14:04 miki-nis

var start = new $odata.Predicate('LastModifiedDateTime', '>=', new $odata.Property(startDate));
var end = new $odata.Predicate('LastModifiedDateTime', '<=', new $odata.Property(endDate));
var combination = $odata.Predicate.and([start, end]);

context.odata()
.expand("PostResources")
.expand("PostComments")
.filter(combination)
.orderBy("CreatedDateTime", "desc");

oleg-demkovych avatar Jun 08 '17 12:06 oleg-demkovych