Monday, 10 April 2017

Loopback custom remote method can't parse JSON-encoded object value

I have created my custom strong-loopback end-point, that accept query condition and callback function, query condition may be a json object like {publishDate: {$lt: new Date(Date() - (1000 * 60 * 60 * 2))}}, but remote method can't parse it. Bellow is my remote method:

JobPosting.jobsByDate = function (groupByCandition, callback) {
   JobPosting.find(groupByCandition,function (err, results) {
     if (err) {
       return callback('err');
     }
     return callback(null, results.length);
   });
}


JobPosting.remoteMethod(
  'jobsByDate',
  {
    accepts: [
      {arg: 'queryCondition', type: 'json', required: true}
    ],
    returns: {root: true},

    http: {path: '/jobsByDate/:queryCondition', verb: 'get'}
});

But when i call it via explorer and pass {publishDate: {$lt: new Date(Date() - (1000 * 60 * 60 * 2))}} gives error:

{
"error": {
"statusCode": 500,
"name": "AssertionError",
"message": "The query argument must be an object",
"actual": false,
"expected": true,
"operator": "==",
"generatedMessage": false,
"stack": "AssertionError: The query argument must be an object\n    at .....
}
}



via jones

No comments:

Post a Comment