softseti-sale-calculator-library
Version:
Sales calculation engine by Softseti
56 lines (49 loc) • 1.48 kB
JavaScript
// src/models/BusinessRuleModel.js
/**
* Business Rule Model for GoRules integration
* @class BusinessRuleModel
*/
class BusinessRuleModel {
constructor(data = {}) {
this.id = data.id || '';
this.name = data.name || '';
this.description = data.description || '';
this.entity_type = data.entity_type || '';
this.trigger_event = data.trigger_event || '';
this.type_rule = data.type_rule || '';
this.company_id = data.company_id || 0;
this.branch_id = data.branch_id || 0;
this.execution_order = data.execution_order || 1;
this.cumulative = data.cumulative || false;
this.valid_from = data.valid_from || null;
this.valid_until = data.valid_until || null;
this.rule_content = data.rule_content || null;
// Optional loop: run the decision per element of a context list.
// { over: "<path to array>", as: "<alias>" }.
this.loop = data.loop || null;
}
/**
* Check if rule is currently active
* @returns {boolean}
*/
isActive() {
const now = new Date();
if (this.valid_from && new Date(this.valid_from) > now) {
return false;
}
if (this.valid_until && new Date(this.valid_until) < now) {
return false;
}
return true;
}
/**
* Validate rule structure
* @returns {boolean}
*/
isValid() {
return this.rule_content &&
this.rule_content.nodes &&
this.rule_content.edges;
}
}
module.exports = BusinessRuleModel;