gpt4 book ai didi

javascript - FeathersJS 中的非 CRUD 路由

转载 作者:行者123 更新时间:2023-11-30 14:37:46 25 4
gpt4 key购买 nike

我有一个服务 results,它处理 feathersjsresults 服务的所有 CRUD 操作。我将如何创建一个路由 /results/:id/hr_bar_graph,它基本上获取特定 id 处的结果并使用结果数据创建条形图。

我目前的代码是:

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

卡在这里有一段时间了。请帮忙。

最佳答案

供引用,来自this issue ,答案是使用params.route和羽毛正常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);
};

关于javascript - FeathersJS 中的非 CRUD 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50155679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com