Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* HELPER FUNCTIONS */
function selectRandomFact() {
const FACTS_ARRAY = ['description', 'released', 'global', 'regions',
'geographies', 'platforms', 'categories', 'products', 'cognitive',
'compliance', 'first', 'certifications', 'competition', 'functions'];
return FACTS_ARRAY[Math.floor(Math.random() * FACTS_ARRAY.length)];
}
function buildFactResponse(factToQuery) {
return new Promise((resolve, reject) => {
if (factToQuery.toString().trim() === 'random') {
factToQuery = selectRandomFact();
}
const query = datastore
.createQuery('AzureFact')
.filter('__key__', '=', datastore.key(['AzureFact', factToQuery]));
datastore
.runQuery(query)
.then(results => {
resolve(results[0][0]);
})
.catch(err => {
console.log(`Error: ${err}`);
reject(`Sorry, I don't know the fact, ${factToQuery}.`);
});
});
}
/* ENTRY POINT */
exports.functionAzureFactsAction = functions.https.onRequest(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment