Skip to content
Chris Manson edited this page Feb 6, 2017 · 3 revisions

The final step before serialisation in the Data Flow is process, which allows you to edit the objects returned from the Database Query before they are passed to the serializer. You can also manually filter or add extra data to the objects in real time if required.

Process implementation

module.exports.autoroute = autorouteJson({
  model: Project,
  find: {
    process: function(results, req) {
       // do your magic here
       // results will be the array of mongoose objects that would have been passed to the serializer
       // req is the express request so you have access to the query params etc. 

       // return a promise that resolves to the processed results
    },
    processOne: function(result, req) {
       // exactly like process but this one runs for singular results e.g. /projects/12
    }
  },
});

You can return a promise from this process function is so that you can do any number of HTTP requests or database lookups with the results before they are passed to the serializer.

Clone this wiki locally