Last active
March 13, 2017 13:41
-
-
Save bezysoftware/f893e2c7f5895e9cdfd8d92baf60f4f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // 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