cqrs-swissknife
Advanced tools
Comparing version 0.4.44 to 0.4.45
'use strict'; | ||
const dotty = require('dotty'); | ||
const { asyncParamApiCallback, noop, toFlatArray } = require('../../utils'); | ||
@@ -14,3 +16,3 @@ | ||
preConditions, | ||
businessRules, | ||
commandBusinessRules, | ||
validator, | ||
@@ -26,7 +28,10 @@ command, | ||
return businessRules.map(f => (current, previous, events, cmd) => { | ||
if (dotty.get(cmd, command.definitions.command.name) === command.name) | ||
return f(current, previous, events, cmd) | ||
return; | ||
}); | ||
return commandBusinessRules.map((f,i) => ({ | ||
name: `${aggregate.context}:${aggregate.name}:businessRule:${command.name}:${0}`, | ||
rule(current, previous, events, cmd) { | ||
if (dotty.get(cmd, command.definitions.command.name) === command.name) | ||
return f(current, previous, events, cmd) | ||
return; | ||
}, | ||
})); | ||
}; | ||
@@ -33,0 +38,0 @@ |
'use strict'; | ||
const dotty = require('dotty'); | ||
const { nextify, asyncParamCustomErrorApiCallback, toFlatArray } = require('../../utils'); | ||
@@ -103,7 +101,4 @@ | ||
if (item.businessRule) { | ||
if (typeof item.businessRule !== 'function') | ||
throw new Error('Invalid command businnes rule. Should be a function'); | ||
result.businessRules.push(item.businessRule); | ||
} | ||
if (item.commandBusinessRule) | ||
result.commandBusinessRules.push(item.commandBusinessRule); | ||
@@ -110,0 +105,0 @@ } |
@@ -20,3 +20,9 @@ 'use strict'; | ||
const commandBusinessRule = (rule) => { | ||
if (!rule || typeof rule !== 'function') | ||
throw new Error('Rule missing or not a function.'); | ||
return { commandBusinessRule: condition }; | ||
}; | ||
const only = { | ||
@@ -39,2 +45,5 @@ ifExists: sharedOnly.ifExists, | ||
}, | ||
after(rule) { // businessRule | ||
return commandBusinessRule(rule) | ||
} | ||
}; | ||
@@ -41,0 +50,0 @@ |
{ | ||
"name": "cqrs-swissknife", | ||
"version": "0.4.44", | ||
"version": "0.4.45", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33174
860