feat(server): ability to assign the base currency as api query when getting latest ex. rate

This commit is contained in:
Ahmed Bouhuolia
2024-01-28 20:10:23 +02:00
parent 1740226294
commit 74a07847a4
6 changed files with 43 additions and 16 deletions

View File

@@ -3,15 +3,23 @@ import { useQuery } from 'react-query';
import QUERY_TYPES from './types';
import useApiRequest from '../useRequest';
interface LatestExchangeRateQuery {
fromCurrency?: string;
toCurrency?: string;
}
/**
* Retrieves latest exchange rate.
* @param {number} customerId - Customer id.
*/
export function useLatestExchangeRate(toCurrency: string, props) {
export function useLatestExchangeRate(
{ toCurrency, fromCurrency }: LatestExchangeRateQuery,
props,
) {
const apiRequest = useApiRequest();
return useQuery(
[QUERY_TYPES.EXCHANGE_RATE, toCurrency],
[QUERY_TYPES.EXCHANGE_RATE, toCurrency, fromCurrency],
() =>
apiRequest
.http({
@@ -19,6 +27,7 @@ export function useLatestExchangeRate(toCurrency: string, props) {
method: 'get',
params: {
to_currency: toCurrency,
from_currency: fromCurrency,
},
})
.then((res) => res.data),