我尝试编写自定义服务,但它根本不起作用。我尝试发布请求并在集合中进行两次更新查询,但我根本不会工作
这是我的代码
// Initializes the `bedrijven` service on path `/bedrijven`
const createService = require('feathers-mongoose');
const createModel = require('../../models/bedrijven.model');
const hooks = require('./bedrijven.hooks');
const filters = require('./bedrijven.filters');
module.exports = function() {
const app = this;
const Model = createModel(app);
const paginate = app.get('paginate');
const options = {
name: 'bedrijven',
Model,
paginate
};
// Initialize our service with any options it requires
app.post('/bedrijven/setfavo', function(req, res) {
Promise.all([
app.service('bedrijven').update({
owner: req.body.userid
}, {
favo: false
}),
app.service('bedrijven').update(req.body._id, {
favo: true
})
]);
});
app.use('/bedrijven', createService(options));
// Get our initialized service so that we can register hooks and filters
const service = app.service('bedrijven');
service.hooks(hooks);
if (service.filter) {
service.filter(filters);
}
};
答案 0 :(得分:0)
确保此文件包含在主app.js文件中。
类似的东西:
const bedrijven = require('./bedrijven/bedrijven.service.js');
app.configure(bedrijven);
您是否有理由不想使用feathers generate service
?它将为您解决这些问题。