Created
April 27, 2020 15:32
-
-
Save shivekkhurana/02b2c78187e9e6dabbb5597404a73184 to your computer and use it in GitHub Desktop.
The JavaScript model of the Karuna 2020 runtime
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
async funtion main() { | |
// call the godown manager and inquire about inventory | |
const inventory = await getGodownStatus(godownManagerContact); | |
// get request details (generally from a whatsapp message) | |
const distributionRequest = await fetchReqestDFetails(); | |
// an id is needed for our records and we'll only distribute at places where we have strong ground control | |
const isRequestValid = await beneficieriesHaveAUniqueId(distributionRequest) && await weTrustRequesters(); | |
if (isRequestValid) { | |
// arrange for transporter who has permissions to move during lockdown | |
const allTransporters = await getTransporters(); | |
const transportersWithPermissions = await Promise.all(allTransporters.filter(async t => await hasPermisson(t))); | |
const selectedTransporter = transportersWithPermissions.reduce(async (availableTransporter, next) => { | |
if (availableTransporter) return availableTransporter(); | |
else { | |
const isTransporterAvailable = await checkAvailability(next); | |
return isTransporterAvailable ? next : null; | |
} | |
}, null); | |
// for the sake of simiplicity, I have omitted the process of sleeping in case no transporter was available | |
// send the inventory | |
await sendInventory(distributionRequest, selectedTransporter); | |
// get proofs of distribution that we can share with our donors | |
await getProofs(distributionRequest); | |
// design proof posts and post on social media | |
await designProofsAndPost(distributionRequest); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment