Skip to content

Instantly share code, notes, and snippets.

@jozolam
Last active November 7, 2021 20:43
Show Gist options
  • Save jozolam/9deed0da254a31c12b26d690042261b9 to your computer and use it in GitHub Desktop.
Save jozolam/9deed0da254a31c12b26d690042261b9 to your computer and use it in GitHub Desktop.
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