jxmono / crud

:fork_and_knife: CRUD for mono
MIT License
0 stars 1 forks source link

Before and after Mongo request #37

Closed IonicaBizau closed 10 years ago

IonicaBizau commented 10 years ago

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

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

or

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

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

// 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(null, request);
  });
});

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