jillix/crud — pull request #37 by IonicaBizau (2014-07-23 08:22:24+00:00)
Title: Before and after Mongo request

After merging this pull request, we will be able to have configurations like this:

```js
{
before: {
create: "createEventB",
read: "readEventB",
update: "updateEventB",
delete: "deleteEventB"
},
after: {
create: "createEventA",
read: "readEventA",
update: "updateEventA",
delete: "deleteEventA"
}
}
```

or

```js
{
before: "catchAllB",
after: "catchAllA"
}
```

---

On the server side, we can listen for these events:

```js
// before event
M.on("crud:createEventB", function (request, callback) {
// do another db request
foo(request, function (err, data) {
if (err) { return callback(err); }
request.query.something = data.something;
callback(err, data, readCount);
});
});

// after event
M.on("crud:createEventA", function (request, err, data, readCount, callback) {
// handle error message
// then send the callback
callback(err, data, readCount);
});
```