@dabafinance/shared-backend v1.7.4
Installation
This is a simple installation guide.
Run the following command to install the package:
npm install @dabafinance/shared-backend
or if you are using Yarn:
yarn add @dabafinance/shared-backend
Quick Start
This package exports a set of resuable classes and functions that can be used across our microservices. The following is a list of the exported classes and functions:
Kafka
- Producer: A class that can be extended to make custom classes for producing to various kafka topics.
- Consumer: A class that can be extended to make custom classes for consuming from various kafka topics.
- Kafka: A class that can be extended to make custom classes for interacting with kafka.
Currency-Conversion
Currency Converter
This package is a simple tool that allows you to convert currencies in real-time, check rates between two currencies, and also pass a manual rate for conversion purposes.
Usage
To use the package, you need to create an instance of the CurrencyConverter
class, passing your API key as a parameter. The class has several methods that allow you to interact with the API.
Methods
getApi(): AxiosInstance
Returns the AxiosInstance
used by the CurrencyConverter
instance.
getCurrencyRate(pair: IPair): Promise<IRateResponse | IError>
Returns the exchange rate between two currencies.
pair
: An object with two properties:from
andto
.
getAvailableCurrencies(): Promise<ICurrencyResponse | IError>
Returns a list of available currencies.
convertCurrencyWithAdjustedRates(input: IConvertWithRate): Promise<IRateResponse | IError>
Converts an amount from one currency to another using a manual rate.
input
: An object with three properties:from
,to
,amount
, andrate
.
convertCurrencyWithMarketRates(payload: IConvert): Promise<ICurrencyResponse | IError>
Converts an amount from one currency to another using the current market rate.
payload
: An object with three properties:from
,to
, andamount
.
Example
import CurrencyConverter from 'currency-converter'
const apiKey = 'YOUR_API_KEY'
const currencyConverter = new CurrencyConverter(apiKey)
// Get the exchange rate between USD and EUR
const rate = await currencyConverter.getCurrencyRate({ from: 'USD', to: 'EUR' })
console.log(rate)
// Get a list of available currencies
const currencies = await currencyConverter.getAvailableCurrencies()
console.log(currencies)
// Convert 10 USD to EUR using a manual rate
const result = await currencyConverter.convertCurrencyWithAdjustedRates({
from: 'USD',
to: 'EUR',
amount: 10,
rate: 0.85
})
console.log(result)
// Convert 10 USD to EUR using the current market rate
const response = await currencyConverter.convertCurrencyWithMarketRates({
from: 'USD',
to: 'EUR',
amount: 10
})
console.log(response)
Auth
authDirective
: A function that checks that the token is available in request headers, decodeds the token and returns the payload.roleDirective
: A function that checks that the token is available in request headers, decodeds the token and extracts the role from the payload and checks if the user has the necessary role to perform the action.
Errors
ErrorService
: A class that exposes a bunch of static methods for creating errors. The errors are returned as aGraphQLError
object.
Base Repository
BaseRepository
: A class that can be extended to make custom classes for interacting with a database.
5 months ago
5 months ago
5 months ago
5 months ago
9 months ago
10 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago