-
-
Save jozolam/9deed0da254a31c12b26d690042261b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createInvoice(client, user): void { | |
validate(user); | |
validate(client); | |
const userPermission = await callApi2(user) // I would keep this sepparate because it should be much faster then rest and can avoid unnecessary calls (if permissions fails) | |
if (validatePermission(userPermission)) { | |
throw exception; | |
} | |
const [invoiceData, orders] = await Promise.all([ // we can call this in parraller | |
callApi2(user), | |
callApi3(client) | |
]) | |
const provision = calculateProvision(client); | |
const invoice = generateInvoce(client, ordes, user, provision); // can (and should) be immutable also all calculations which does not requiere dependecies can be encapsulated | |
return invoice; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment