I come from a database programming background (e.g., Oracle PL/SQL) and had to learn some typescript for a recent project due to the difficulty in hiring web developers. I did ok - it was very clunky back-endish type code I was writing. It just had to work and it did.
I feel like there's a programming modality familiar to the world of databases that I can't see how to accomplish in Typescript. Consider this working fragment of code to evaluate a business rule:
public br_12(contractBid: WFO.ContractBid) {
const condition1 = (contractBid.n_tax_per <= 0.003);
const condition2 = (this.br_12(contractBid) === 0 && this.br_18(contractBid)) === 0 && contractBid.n_tax_per <= 0.005;
if (condition1 || condition2)
{
return Math.ceil ( ( this.br_2(contractBid) * contractBid.n_tax_per) * 100 / 100 ) ;
} else {
return 0;
}
}
I would like to be able to store the business rules, specifically the conditions, externally in a JSON file - or other external data source - and sometimes reference them arbitrarily and programmatically. And be able to update them without "changing any code" - of course I know the app would have to be rebuilt and redeployed when they change. So to write very rough sample code:
{
"business rules conditions": {
"condition1": "(contractBid.n_tax_per <= 0.003)",
"condition2": "(this.br_12(contractBid) === 0 && this.br_18(contractBid)) === 0 && contractBid.n_tax_per <= 0.005"
}
}
public br_12(contractBid: WFO.ContractBid) {
if (this.external.condition1 || this.external.condition2)
{
return Math.ceil ( ( this.br_2(contractBid) * contractBid.n_tax_per) * 100 / 100 ) ;
} else {
return 0;
}
}
Nevermind that I'm crazy to want to do such a thing - is there a way to do it?