Skip to content

Commit 1fa7b44

Browse files
author
Ace Nassri
committed
Fix bugs
1 parent 9620c9b commit 1fa7b44

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Diff for: src/currencyservice/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
client.js
12
node_modules/

Diff for: src/currencyservice/client.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,22 @@ const request = {
3737
to_code: 'CHF'
3838
};
3939

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+
4052
client.convert(request, function (err, response) {
4153
if (err) {
42-
console.error(err);
54+
console.error(`Error in convert: ${err}`);
4355
} else {
44-
const amount = response.amount;
45-
console.log(`OUTPUT: ${amount.decimal}.${amount.fractional}`);
56+
console.log(`Convert: ${_moneyToString(request.from)} to ${_moneyToString(response)}`);
4657
}
4758
});

Diff for: src/currencyservice/server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function _carry (amount) {
6565
*/
6666
function getSupportedCurrencies (call, callback) {
6767
_getCurrencyData((data) => {
68-
callback(null, {currency_codes: data.keys()});
68+
callback(null, {currency_codes: Object.keys(data)});
6969
});
7070
}
7171

@@ -91,7 +91,7 @@ function convert (call, callback) {
9191
});
9292
target.fractional = Math.round(target.fractional);
9393

94-
callback(null, {amount: target});
94+
callback(null, {currency_code: request.to_code, amount: target});
9595
});
9696
} catch (err) {
9797
callback(err.message);

0 commit comments

Comments
 (0)