-
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
Allow overriding default CRUD methods #12
Comments
+1 |
It could also use Uberproto which is what e.g. feathers-memory and feathers-mongodb use. That way you'd get a common inheritance pattern like: var Memory = require('feathers-memory');
var TodoService = Memory.extend({
get: function(id, params, callback) {
this._super(id, params, function(error, data) {
if(error) {
return callback(error);
}
if(data.user !== params.user.id) {
return callback(new Error('You can not access this todo'));
}
callback(null, data);
});
}
});
// Add a mixin that adds createdAt and updateAt timestamps
TodoService.mixin(timeStampMixin); |
Easy extension should be possible with feathers-hooks no. With a boilerplate like: // Get Feathers
var feathers = require('feathers');
// Get Hooks
var hooks = require('feathers-hooks');
// Get Mongoose
var mongoose = require('mongoose');
// Get Mongoose-Service
var mongooseService = require('feathers-mongoose');
// Connect to your MongoDB
mongoose.connect('mongodb://localhost/test');
// Create your Mongoose-Service, for a `User`
var userService = mongooseService('user', {
email: {type : String, required : true, index: {unique: true, dropDups: true}},
firstName: {type : String, required : true},
lastName: {type : String, required : true},
age: {type : Number, required : true},
password: {type : String, required : true, select: false},
skills: {type : Array, required : true}
}, mongoose);
// Setup Feathers
var app = feathers();
// Configure Feathers
app.use(feathers.logger('dev')); // For debugging purposes.
// ................
var port = 8080;
// ................
app.configure(hooks())
.configure(feathers.socketio())
.use('/user', userService); // <-- Register your custom Mongoose-Service with Feathers You can e.g. add a // Add a before create hook
app.lookup('/user').before({
create: function(hook, next) {
// override default logic
hook.data.createdAt = new Date();
next();
}
});
app.listen(port, function() {
console.log('Express server listening on port ' + port);
}); Should we add that to the documentation? |
Once PR #18 lands you'll be able to extend services explicitly or use hooks. feathers-hooks has a bunch of documentation on how they can be used, and we also have a more comprehensive guide on using hooks for validation. |
There might be a time when there is a need to override one of the methods. I'm thinking:
Of course we can just override the method directly but if it's passed in as an option we could avoid setting the default on Store
The text was updated successfully, but these errors were encountered: