This commit is contained in:
Ace Nassri 2018-06-22 14:51:01 -07:00
parent 9620c9bb1c
commit 1fa7b44c83
3 changed files with 18 additions and 6 deletions

View File

@ -1 +1,2 @@
client.js
node_modules/ node_modules/

View File

@ -37,11 +37,22 @@ const request = {
to_code: 'CHF' to_code: 'CHF'
}; };
client.convert(request, function (err, response) { function _moneyToString (m) {
return `${m.amount.decimal}.${m.amount.fractional} ${m.currency_code}`;
}
client.getSupportedCurrencies({}, (err, response) => {
if (err) { if (err) {
console.error(err); console.error(`Error in getSupportedCurrencies: ${err}`);
} else { } else {
const amount = response.amount; console.log(`Currency codes: ${response.currency_codes}`);
console.log(`OUTPUT: ${amount.decimal}.${amount.fractional}`); }
});
client.convert(request, function (err, response) {
if (err) {
console.error(`Error in convert: ${err}`);
} else {
console.log(`Convert: ${_moneyToString(request.from)} to ${_moneyToString(response)}`);
} }
}); });

View File

@ -65,7 +65,7 @@ function _carry (amount) {
*/ */
function getSupportedCurrencies (call, callback) { function getSupportedCurrencies (call, callback) {
_getCurrencyData((data) => { _getCurrencyData((data) => {
callback(null, {currency_codes: data.keys()}); callback(null, {currency_codes: Object.keys(data)});
}); });
} }
@ -91,7 +91,7 @@ function convert (call, callback) {
}); });
target.fractional = Math.round(target.fractional); target.fractional = Math.round(target.fractional);
callback(null, {amount: target}); callback(null, {currency_code: request.to_code, amount: target});
}); });
} catch (err) { } catch (err) {
callback(err.message); callback(err.message);