Fix bugs
This commit is contained in:
parent
9620c9bb1c
commit
1fa7b44c83
3 changed files with 18 additions and 6 deletions
|
@ -1 +1,2 @@
|
|||
client.js
|
||||
node_modules/
|
||||
|
|
|
@ -37,11 +37,22 @@ const request = {
|
|||
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) {
|
||||
console.error(err);
|
||||
console.error(`Error in getSupportedCurrencies: ${err}`);
|
||||
} else {
|
||||
const amount = response.amount;
|
||||
console.log(`OUTPUT: ${amount.decimal}.${amount.fractional}`);
|
||||
console.log(`Currency codes: ${response.currency_codes}`);
|
||||
}
|
||||
});
|
||||
|
||||
client.convert(request, function (err, response) {
|
||||
if (err) {
|
||||
console.error(`Error in convert: ${err}`);
|
||||
} else {
|
||||
console.log(`Convert: ${_moneyToString(request.from)} to ${_moneyToString(response)}`);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -65,7 +65,7 @@ function _carry (amount) {
|
|||
*/
|
||||
function getSupportedCurrencies (call, callback) {
|
||||
_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);
|
||||
|
||||
callback(null, {amount: target});
|
||||
callback(null, {currency_code: request.to_code, amount: target});
|
||||
});
|
||||
} catch (err) {
|
||||
callback(err.message);
|
||||
|
|
Loading…
Reference in a new issue