0
votes

I am currently designing a sales application (Angular 6 + Bootstrap) to be a responsive application for one of the telecom operators and my system users are more than 10K user who is accessing the system daily for sales activities on the same time and i have a lot of business rules which needs to run sometimes sequential and sometimes parallel and sometimes its client side business rules and sometimes run based on web-services calls REST.

in another application (HTML5 & JQUERY) we used an action chain concept which is designed manually and each action in the chain takes the HTML element as an input and start applying the logic and then forward to next action or fail and end the chain.

my question is how to apply the business rules in Angular application in chain concept considering that the whole backend is RESTful web services.?

2
Angular uses RxJS which supports chaining observables, that's probably where you start looking at. You can learn some of it from learn-rxjs, thought it might have some out-of-date information.Joshua Chan
let us have an example from what i need to do in my application to be more clear: let us say i have a text field which will have the customer mobile number, i need to apply the following business rules on this mobile number: 1- check the mobile number status in the backend system (external system) through rest web service to make sure its valid. 2- check the mobile number in another system that the owner is the same as the current customer using the identity number. 3- check if the customer doesn’t have any outstanding amount of money on his account on the billing systemMohamed

2 Answers

2
votes

Thanks for your support ..

I have developed it manually like OOP for my actions/validations and Angular controller will manage running the list of actions if exist.

-1
votes

One way to implement the checking as you've said in your example scenario:

First, we assume that rules 1, 2 and 3 are independent and should be checked parallel:

Note that the proper way to call API in Angular is through a service.

let checkNumber1 = this.http.post('https://example.com/api/checkNumber', { mobileNo: '0123920802' });
let checkNumber2 = this.http.post('https://example2.com/api/checkNumber', { mobileNo: '0123920802' });
let checkOutstanding = this.http.post('https://example.com/api/checkOutstanding', { userId: 23910231 });

forkJoin([checkNumber1, checkNumber2, checkOutstanding]).subscribe(results => {
    // results[0] is our result from checkNumber1
    // results[1] is our result from checkNumber2
    // results[2] is our result from checkOutstanding
    if (results[0] && results[1] && results[2]) {
        // if all checks return true 
        proceed();
    } else {
        error();
    }
});

What if you want to do the checking sequentially, one possible way would be:

checkNumber1.subscribe((result) => {
    if (result) {
        checkNumber2.subscribe((result) => {
            if (result) {
                checkOutstanding.subscribe((result) => {
                    if (result) {
                        proceed();
                    }
                });
            }
        });
    }
});