File tree 3 files changed +17
-5
lines changed
3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change
1
+ client.js
1
2
node_modules /
Original file line number Diff line number Diff line change @@ -37,11 +37,22 @@ const request = {
37
37
to_code : 'CHF'
38
38
} ;
39
39
40
+ function _moneyToString ( m ) {
41
+ return `${ m . amount . decimal } .${ m . amount . fractional } ${ m . currency_code } ` ;
42
+ }
43
+
44
+ client . getSupportedCurrencies ( { } , ( err , response ) => {
45
+ if ( err ) {
46
+ console . error ( `Error in getSupportedCurrencies: ${ err } ` ) ;
47
+ } else {
48
+ console . log ( `Currency codes: ${ response . currency_codes } ` ) ;
49
+ }
50
+ } ) ;
51
+
40
52
client . convert ( request , function ( err , response ) {
41
53
if ( err ) {
42
- console . error ( err ) ;
54
+ console . error ( `Error in convert: ${ err } ` ) ;
43
55
} else {
44
- const amount = response . amount ;
45
- console . log ( `OUTPUT: ${ amount . decimal } .${ amount . fractional } ` ) ;
56
+ console . log ( `Convert: ${ _moneyToString ( request . from ) } to ${ _moneyToString ( response ) } ` ) ;
46
57
}
47
58
} ) ;
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ function _carry (amount) {
65
65
*/
66
66
function getSupportedCurrencies ( call , callback ) {
67
67
_getCurrencyData ( ( data ) => {
68
- callback ( null , { currency_codes : data . keys ( ) } ) ;
68
+ callback ( null , { currency_codes : Object . keys ( data ) } ) ;
69
69
} ) ;
70
70
}
71
71
@@ -91,7 +91,7 @@ function convert (call, callback) {
91
91
} ) ;
92
92
target . fractional = Math . round ( target . fractional ) ;
93
93
94
- callback ( null , { amount : target } ) ;
94
+ callback ( null , { currency_code : request . to_code , amount : target } ) ;
95
95
} ) ;
96
96
} catch ( err ) {
97
97
callback ( err . message ) ;
You can’t perform that action at this time.
0 commit comments