首页 > 解决方案 > FeathersJS 中的非 CRUD 路由

问题描述

我有一项服务可以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);
};

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

标签: javascriptfeathersjsfeathers-sequelizefeathers-hookfeathers-service

解决方案


作为参考,从这个问题,答案是使用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);
};

推荐阅读