41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import type { QueryClient } from "@tanstack/react-query";
|
|
import { apiQueryClient, type paths } from "@/shared/api";
|
|
|
|
type TbankConnectionStatus =
|
|
paths["/api/v1/tbank-connection"]["get"]["responses"][200]["content"]["application/json"];
|
|
|
|
const brokerageAccountsPath = "/api/v1/brokerage-accounts";
|
|
|
|
const tbankConnectionQueryOptions = () =>
|
|
apiQueryClient.queryOptions("get", "/api/v1/tbank-connection");
|
|
|
|
const tbankConnectionQueryKey = tbankConnectionQueryOptions().queryKey;
|
|
|
|
function commitTbankConnectionBoundary(
|
|
queryClient: QueryClient,
|
|
status: TbankConnectionStatus,
|
|
) {
|
|
queryClient.setQueryData(tbankConnectionQueryKey, status);
|
|
void queryClient.resetQueries({
|
|
predicate: ({ queryKey }) => {
|
|
const [method, path] = queryKey;
|
|
return (
|
|
method === "get" &&
|
|
typeof path === "string" &&
|
|
(path === "/api/v1/bonds" ||
|
|
path.startsWith("/api/v1/bonds/") ||
|
|
path === "/api/v1/stocks" ||
|
|
path.startsWith("/api/v1/stocks/") ||
|
|
path === brokerageAccountsPath ||
|
|
path.startsWith(`${brokerageAccountsPath}/`))
|
|
);
|
|
},
|
|
});
|
|
}
|
|
|
|
export {
|
|
commitTbankConnectionBoundary,
|
|
type TbankConnectionStatus,
|
|
tbankConnectionQueryOptions,
|
|
};
|