首页 文章

如何在REST API中按日期查询

提问于
浏览
-1

我正在使用loopback生成REST API并且有一个考勤表,其中包含学生的出勤记录 . 以下查询给出了下面给出的结果 .

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
  }
]

但我希望通过这样的查询获得相同的结果

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

时间不应该是必要的......或者认为它是一个未知的实体 . 我怎样才能得到与上面相同的结果?

1 回答

  • 0

    目前环回不支持类似的东西 . 随意打开一个问题,但这适用于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
    

    您也可以覆盖find方法来为您执行此操作 .

    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);
    };
    

相关问题