-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to override service methods #26
Comments
found solution @ feathers-mongodb git, just needed to extend the serivce. var mongoose = require('feathers-mongoose');
var Proto = require('uberproto');
var MessageService = mongoose.Service.extend({
created: function (data, params, callback) {
//TODO Write logic
return callback(null, data);
},
updated: function (data, params, callback) {
//TODO Write logic
return callback(null, false);
}
});
module.exports = function (modelName, schema, options) {
return Proto.create.call(MessageService, modelName, schema, options);
};
module.exports.Service = MessageService; |
That is correct. The newer versions will use ES6 classes instead of Uberproto but that is still in the works. Our preferred method though is through Hooks (https://github.com/feathersjs/feathers-hooks). For example, you could add a var mongoose = require('feathers-mongoose');
var Proto = require('uberproto');
var MessageService = mongoose.Service.extend({
created: function (data, params, callback) {
data.created_at = new Date();
this._super(data, params, callback);
},
update: function (id, data, params, callback) {
data.created_at = new Date();
this._super(data, params, callback);
}
}); With hooks that would look like this: function timestamp(name) {
return function(hook, next) {
hook.data[name] = new Date();
next();
}
}
app.service('users')
// Add updated_at and created_at
.before({
create: timestamp('created_at'),
update: timestamp('updated_at'),
patch: timestamp('updated_at')
}); The difference is that you can attach the |
By default feathers broadcast events to all connected clients when using socket.io mode, this could be fatal and feathers service provides a way to override default methods (created, find etc). How do I do the same with MongooseService?
The text was updated successfully, but these errors were encountered: