Skip to content

Instantly share code, notes, and snippets.

@bezysoftware
Last active March 13, 2017 13:41
Show Gist options
  • Select an option

  • Save bezysoftware/f893e2c7f5895e9cdfd8d92baf60f4f6 to your computer and use it in GitHub Desktop.

Select an option

Save bezysoftware/f893e2c7f5895e9cdfd8d92baf60f4f6 to your computer and use it in GitHub Desktop.
// refresh currency rates
export let refreshExchangeRates = functions
.https
.onRequest(async (request, response) =>
{
await refreshExchangeRates();
response.end();
});
// functions to pull latest exchange rates and store them
async function refreshExchangeRates()
{
let allRates = await getAllCurrencyRates();
let mappedRates = allRates.reduce((objs, rate) => {
objs[rate.currency] = rate.rate.toString();
return objs;
}, {});
let db = admin.database();
let date = moment().format('YYYYMMDD');
let todayRef = db.ref('exchangeRatesToUsd/' + date)
let latestRef = db.ref('exchangeRatesToUsd/latest');
await todayRef.set(mappedRates);
await latestRef.set(mappedRates);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment