简体   繁体   中英

How to query by date in REST API

I am using loopback to generate REST API and having an Attendance table which contain the attendance record of students. Following query gives me the result as given below.

http://localhost:3000/api/attendances?filter[where][date]=2015-08-27T05:26:33.000Z

Result:

[
  {
    "regno": "1414",
    "name": "Salman",
    "reason": "on leave",
    "class": "R",
    "date": "2015-08-27T05:26:33.000Z",
    "status": true,
    "id": 1
  }
]

but I want to get the same result by querying like that

http://localhost:3000/api/attendances?filter[where][date]=2015-08-27

ie Time should not be necessory.. or consider it an unknown entity. How can I get the same result as above ?

Currently loopback doesn't have support for something like that. Feel free to open an issue, but this works for me with postgresql:

http://localhost:3000/api/Attendances?filter[where][start][between][0]=2015-08-29&filter[where][start][between][1]=2015-08-29T23:59:59.999Z

You can also override the find method to do this for you.

var originalFind = Attendance.find;
Attendance.find = function(filter) {
    if (filter && filter.where && filter.where.date) {
       // check if the date and convert the filter if needed.
    }
    return originalFind.apply(this, arguments);
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM