fix: update use-get-health.ts (#2553)
* update getHealth function to use options param * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
c444a6905c
commit
46f82a6af4
1 changed files with 7 additions and 22 deletions
|
|
@ -14,39 +14,24 @@ interface getHealthResponse {
|
||||||
export const useGetHealthQuery: useQueryFunctionType<
|
export const useGetHealthQuery: useQueryFunctionType<
|
||||||
undefined,
|
undefined,
|
||||||
getHealthResponse
|
getHealthResponse
|
||||||
> = (_, onFetch) => {
|
> = (_, options) => {
|
||||||
const { query } = UseRequestProcessor();
|
const { query } = UseRequestProcessor();
|
||||||
|
|
||||||
const responseFn = (data: getHealthResponse) => {
|
|
||||||
if (!onFetch) return data;
|
|
||||||
if (typeof onFetch === "function") return onFetch(data);
|
|
||||||
switch (onFetch) {
|
|
||||||
default:
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the health status of the API.
|
* Fetches the health status of the API.
|
||||||
*
|
*
|
||||||
* @returns {Promise<AxiosResponse<TransactionsResponse>>} A promise that resolves to an AxiosResponse containing the health status.
|
* @returns {Promise<AxiosResponse<TransactionsResponse>>} A promise that resolves to an AxiosResponse containing the health status.
|
||||||
*/
|
*/
|
||||||
async function getHealthFn() {
|
async function getHealthFn() {
|
||||||
return await api.get("/health_check");
|
return (await api.get("/health_check")).data;
|
||||||
// Health is the only endpoint that doesn't require /api/v1
|
// Health is the only endpoint that doesn't require /api/v1
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryResult = query(
|
const queryResult = query(["useGetHealthQuery"], getHealthFn, {
|
||||||
["useGetHealthQuery"],
|
placeholderData: keepPreviousData,
|
||||||
async () => {
|
refetchInterval: 20000,
|
||||||
const result = await getHealthFn();
|
...options,
|
||||||
return responseFn(result.data);
|
});
|
||||||
},
|
|
||||||
{
|
|
||||||
placeholderData: keepPreviousData,
|
|
||||||
refetchInterval: 20000,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return queryResult;
|
return queryResult;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue