/**
 * Module dependencies
 */
var actionUtil = require("./_util/actionUtil");
/**
 * Find Records
 *
 *  get   /:modelIdentity
 *
 * An API call to find and return model instances from the data adapter
 * using the specified criteria.
 *
 */

module.exports = function findRecords(req, res) {
  // Look up the model
  var Model = actionUtil.parseModel(req);

  // Lookup for records that match the specified criteria

  var queryParams = JsonApiService.deserialize(req.query.filter) || null;

  // This allows to more advance filtering things like '?filter[date]={"<":"YYYY-MM-DD"}'
  let params = Object.entries(queryParams).map(([key, value]) => {
    try {
      var val = JSON.parse(value);
      return [key, val];
    } catch (err) {
      return [key, value];
    }
  });
  queryParams = params.reduce(
    (qp, [key, value]) => ({ ...qp, [key]: value }),
    {}
  );
  var query = Model.find(queryParams);

  // populate as required
  actionUtil.populateEach(req, query);

  query.exec((err, matchingRecords) => {
    if (err) return res.serverError(err);

    return res.ok(matchingRecords);
  });
};

@@ -487,16 +487,39 @@
  null;%0A%0A
+  if (queryParams) %7B%0A  
   // Thi
@@ -600,16 +600,18 @@
 M-DD%22%7D'%0A
+  
   let pa
@@ -677,14 +677,18 @@
     
+ 
+ 
 try %7B%0A
+  
     
@@ -720,24 +720,26 @@
 lue);%0A      
+  
 return %5Bkey,
@@ -745,16 +745,18 @@
 , val%5D;%0A
+  
     %7D ca
@@ -769,24 +769,26 @@
 rr) %7B%0A      
+  
 return %5Bkey,
@@ -804,16 +804,22 @@
     
-%7D%0A
+  %7D%0A  
   %7D);%0A
+  
   qu
@@ -845,16 +845,18 @@
 reduce(%0A
+  
     (qp,
@@ -908,16 +908,24 @@
     
+  
 %7B%7D%0A
+  
   );%0A
+  %7D%0A
   va

add conditional branch to prevent crash on request without query params