Skip to content

Instantly share code, notes, and snippets.

@mlhamel mlhamel/gist:2697771
Created May 14, 2012

Embed
What would you like to do?
ContactSchema.pre('save', function(next) {
var self = this;
Step(
function count() {
Message
.find({author: self.user, recipient: self.contact})
.count(this.parallel());
Message
.find({author: self.contact, recipient: self.user})
.count(this.parallel());
},
function saveCount(err, count_1, count_2) {
if(err) {
return next(new exception.Fatal(err));
} else {
self.count = count_1 + count_2;
self.save(next);
}
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.