简体   繁体   中英

Non CRUD Route in FeathersJS

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM