Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 4a233f7

Browse files
committed
feat: ✨ Convert route for currencies
1 parent 56ddbb3 commit 4a233f7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Server/Routes/v3/Currencies/Currencies.config.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Application, Router } from "express";
22
import { APIError, APISuccess } from "../../../../Lib/Response";
33
import { PaypalCurrencies } from "../../../../Payments/Currencies/Paypal.currencies";
4-
import { currencyCodes, GetCurrencySymbol, TPaymentCurrency } from '../../../../Lib/Currencies';
4+
import { convertCurrency, currencyCodes, GetCurrencySymbol, TPaymentCurrency } from '../../../../Lib/Currencies';
55
export = CurrenciesRouter;
66
class CurrenciesRouter
77
{
@@ -29,7 +29,17 @@ class CurrenciesRouter
2929
if(!code)
3030
return APIError("Invalid code")(res);
3131
return APISuccess(GetCurrencySymbol(code))(res);
32-
})
32+
});
33+
34+
this.router.get("/convert/:from/:to/:amount", async (req, res) =>
35+
{
36+
const from = currencyCodes.find(c => c === req.params.from.toUpperCase()) as TPaymentCurrency;
37+
const to = currencyCodes.find(c => c === req.params.to.toUpperCase()) as TPaymentCurrency;
38+
const amount = Number(req.params.amount);
39+
if(!from || !to || !amount)
40+
return APIError("Invalid parameters")(res);
41+
return APISuccess(await convertCurrency(amount, from, to))(res);
42+
});
3343

3444
}
3545

0 commit comments

Comments
 (0)