crazytoad/meteor-collectionapi — pull request #3 by andreasgl (2012-08-14 23:39:50+00:00)
Title: A callback that is called right before the collection is modified/queried.

Hey crazytoad,

thanks for the great project. But I needed some extra features. Perhaps this is also interesting for you:

You can now specify a function for each rest method, which will be called right before the collection will be modified/queried. If you return false the action will be canceled, with returning true the action will take place. Editing the object before POST/PUT actions is also possible.

Example:

```js
collectionApi.addCollection(ToDos, 'todos', {methods: ['POST', 'GET', 'PUT', 'DELETE'], before: {
POST: function(todo) {
if(todo.PropX === 'something') {
todo.PropY = 'something else';
return true;
}
return false;
},

GET: function(collectionID, todos) {
for(i=0; i < todos.length;i++)
{
if(todos[i].Secret) {
todos[i] = null;
}
}
return true;
},

PUT: function(collectionID, todo, newValues) {
if (todo.PropX === 'something')
{
return true;
}
return false;
},

DELETE: function(collectionID, todo) {
if (todo.safe)
{
return false;
}
return true;
}
}});
```