Skip to content

Instantly share code, notes, and snippets.

@geshan
Created October 10, 2018 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geshan/1f76e5ebb3c15fd3c147c6c97420f923 to your computer and use it in GitHub Desktop.
Save geshan/1f76e5ebb3c15fd3c147c6c97420f923 to your computer and use it in GitHub Desktop.
exchange rates part
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