Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix for async business rules

  • Loading branch information...
commit d2636c2aeafac0590b03a13eb793e83716d10ab6 1 parent 3fd1317
@adrai authored
Showing with 13 additions and 10 deletions.
  1. +4 −0 README.md
  2. +8 −9 lib/bases/aggregateBase.js
  3. +1 −1  package.json
4 README.md
@@ -78,6 +78,10 @@ See [tests](https://github.com/adrai/node-cqrs-domain/tree/master/test) for deta
# Release Notes
+## v0.5.3
+
+- fix for async business rules (issue [#13](https://github.com/adrai/node-cqrs-domain/issues/13))
+
## v0.5.2
- fix commandDispatcher if no commandqueue is used
View
17 lib/bases/aggregateBase.js
@@ -100,7 +100,7 @@ Aggregate.prototype = {
if(!this.businessRules) return callback(null);
- this.businessRules.forEach(function(rule, index) {
+ async.each(this.businessRules, function(rule, callback) {
rule.call(self, changedAttributes, self.previousAttributes, self.uncommittedEvents, function(ruleId, message) {
if (ruleId) {
if (!message) {
@@ -109,15 +109,14 @@ Aggregate.prototype = {
}
keys.push({ type: 'businessRule', ruleId: ruleId, message: message });
}
+ callback(null);
});
-
- if (index === self.businessRules.length - 1) {
- if (keys.length > 0) {
- self.attributes = self.previousAttributes;
- callback(keys);
- } else {
- callback(null);
- }
+ }, function() {
+ if (keys.length > 0) {
+ self.attributes = self.previousAttributes;
+ callback(keys);
+ } else {
+ callback(null);
}
});
}
View
2  package.json
@@ -1,7 +1,7 @@
{
"author": "adrai",
"name": "cqrs-domain",
- "version": "0.5.2",
+ "version": "0.5.3",
"private": false,
"main": "index.js",
"engines": {
Please sign in to comment.
Something went wrong with that request. Please try again.