1.0.7 • Published 4 years ago

ami_business_rules v1.0.7

Weekly downloads
-
License
GPLv3
Repository
github
Last release
4 years ago

Business Rules

Simple interface to create custom business rules that you can process on your code and check if pass or not

Example

import { Rule } from "../main";
import { RulesManager } from "ami_business_rules";

export class TestRule implements Rule {
    public status: boolean;
    public code: string;
    public msg: string;
    private data: boolean;
    constructor(code: string, data: boolean) {
        this.code = code;
        this.data = data;
        this.status = true;
    }
    public process(): boolean {
        console.log("Processing " + this.code);
        if (!this.data){
            this.msg = "Fails rule";
            this.status = false;
        } else {
           this.msg = "Pass rule";
        }
        return this.status;
    }


}

var ruleObject = new TestRule();
var rm = RulesManager.get();

rm.addRule(ruleObject, "RuleGroupName");

var result = rm.process("RuleGroupName");

if (!result){
    console.log("FAILS");
} else {
    console.log("PASS");
}

for(var rule of rm.getAllRules("RuleGroupName")){
    console.log("******");
    console.log("Rule Name: " + rule.code);
    console.log("Rule status: " + rule.status.toString());
    console.log("Rule msg: " + rule.msg);
}

Run test

You can run the test

npm run start-test

Contributing

Refer to CONTRIBUTING.md

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago