UNPKG

@hiki9/rich-domain

Version:

Rich Domain is a library that provides a set of tools to help you build complex business logic in NodeJS using Domain Driven Design principles.

22 lines 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApplyRulesOnlyAfterCommitsSync = void 0; /** * @description This decorator will ensure that the business rules will be applied only after the commit. * This will help in case your method has a lot of commits, and you want to apply the rules only after the last commit. * that means, if you update your entity X times in a method, the rules will be applied only after the method ends. */ function ApplyRulesOnlyAfterCommitsSync() { return function (_, __, descriptor) { const originalMethod = descriptor.value; descriptor.value = function (...args) { this['rulesIsLocked'] = true; const result = originalMethod.apply(this, args); this['rulesIsLocked'] = false; this['ensureBusinessRules'](); return result; }; }; } exports.ApplyRulesOnlyAfterCommitsSync = ApplyRulesOnlyAfterCommitsSync; //# sourceMappingURL=apply-rules-only-after-ends.js.map