Created
October 10, 2018 11:23
-
-
Save geshan/1f76e5ebb3c15fd3c147c6c97420f923 to your computer and use it in GitHub Desktop.
exchange rates part
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 function get(params) { | |
const today = new Date().toISOString().split('T')[0]; | |
const {fromCurrency='AUD', toCurrency='USD', onDate=today} = params; | |
let exchangeRates = await db.query( | |
`SELECT rate, created_at FROM exchange_rates WHERE from_currency = ? AND to_currency = ? AND on_date = ?`, | |
[fromCurrency, toCurrency, onDate] | |
); | |
if (exchangeRates.length) { | |
const rate = Number(exchangeRates[0].rate); | |
console.log(`Found exchange rate of ${rate} for ${fromCurrency} to ${toCurrency} of ${onDate} in the db`); | |
return {fromCurrency, toCurrency, onDate, rate}; | |
} | |
return getExternal(fromCurrency, toCurrency, onDate); | |
} | |
module.exports = { | |
get | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment