1

I have a service results that handles all CRUD Operations for the results service in feathersjs. How would I create a route /results/:id/hr_bar_graph which basically fetches the result at that particular id and uses the resulting data to create an bar graph.

My code currently is:

module.exports = function (app) {


const Model = createModel(app);
  const paginate = app.get('paginate');

  const options = {
    name: 'results',
    Model,
    paginate
  };



// Initialize our service with any options it requires
  app.use('/results', createService(options));

  app.use('/results/:id/hr_bargraph_image', {
    find(id, params){
      this.app.service('results').get(id)
        .then(function(response){
          console.log(response);
        })
        .cathc(function(error){
          console.log(error);
        })
      return Promise.resolve({
        imageData: ''
      });
    }
  });

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('results');

  service.hooks(hooks);
};

Been stuck here for a while now. Please help.

dadidaochieng
  • 105
  • 13

1 Answers1

2

For reference, from this issue, the answer is to use params.route and Feathers normal find(params):

module.exports = function (app) {
  const Model = createModel(app);
  const paginate = app.get('paginate');

  const options = {
    name: 'results',
    Model,
    paginate
  };

  // Initialize our service with any options it requires
  app.use('/results', createService(options));

  app.use('/results/:id/hr_bargraph_image', {
    async find(params){
      const { id } = params.route;
      const results = await app.service('results').get(id);

      return {
        imageData: ''
      };
    }
  });

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('results');

  service.hooks(hooks);
};
Daff
  • 43,734
  • 9
  • 106
  • 120
  • How do I apply the same hooks I have on the results service to this custom service? Without affecting the working of the `results` service – dadidaochieng May 09 '18 at 14:04