1

我有一项服务可以results处理. 我将如何创建一个基本上以该特定 id 获取结果并使用结果数据创建条形图的路由。resultsfeathersjs/results/:id/hr_bar_graph

我目前的代码是:

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

现在被困在这里一段时间了。请帮忙。

4

1 回答 1

2

作为参考,从这个问题,答案是使用params.route和 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);
};
于 2018-05-04T15:44:36.623 回答