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

Commit

Permalink
feat: ✨ Convert route for currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolfx committed Mar 15, 2022
1 parent 56ddbb3 commit 4a233f7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Server/Routes/v3/Currencies/Currencies.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Application, Router } from "express";
import { APIError, APISuccess } from "../../../../Lib/Response";
import { PaypalCurrencies } from "../../../../Payments/Currencies/Paypal.currencies";
import { currencyCodes, GetCurrencySymbol, TPaymentCurrency } from '../../../../Lib/Currencies';
import { convertCurrency, currencyCodes, GetCurrencySymbol, TPaymentCurrency } from '../../../../Lib/Currencies';
export = CurrenciesRouter;
class CurrenciesRouter
{
Expand Down Expand Up @@ -29,7 +29,17 @@ class CurrenciesRouter
if(!code)
return APIError("Invalid code")(res);
return APISuccess(GetCurrencySymbol(code))(res);
})
});

this.router.get("/convert/:from/:to/:amount", async (req, res) =>
{
const from = currencyCodes.find(c => c === req.params.from.toUpperCase()) as TPaymentCurrency;
const to = currencyCodes.find(c => c === req.params.to.toUpperCase()) as TPaymentCurrency;
const amount = Number(req.params.amount);
if(!from || !to || !amount)
return APIError("Invalid parameters")(res);
return APISuccess(await convertCurrency(amount, from, to))(res);
});

}

Expand Down

0 comments on commit 4a233f7

Please sign in to comment.