Files
frontend/src/entities/broker-operation/api/useBrokerageOperations.ts
T
ksv741 3eafad2657
Frontend security / security (push) Successful in 9s
Frontend verify / verify (push) Failing after 37m50s
Frontend security / security (pull_request) Successful in 9s
Frontend verify / verify (pull_request) Failing after 42m10s
Conventional commits / commits (pull_request) Successful in 29s
chore: finish frontend ESLint migration #18
Enable every plugin recommended preset and replace Biome with ESLint formatting.

Preserve API contracts and JSX whitespace; verify source, tests, builds and tooling.
2026-09-28 07:31:28 +03:00

71 lines
1.9 KiB
TypeScript

import { apiQueryClient, type paths, useResourceQuery } from "@/shared/api";
type BrokerageOperation = NonNullable<
OperationsEndpoint["responses"][200]["content"]["application/json"]["data"]
>["items"][number];
type BrokerageOperationsQuery = Omit<
NonNullable<OperationsEndpoint["parameters"]["query"]>,
"sync"
>;
type OperationCategory = BrokerageOperation["category"];
type OperationsEndpoint
= paths["/api/v1/brokerage-accounts/{accountId}/operations"]["get"];
const operationCategories = [
"trade",
"income",
"tax",
"fee",
"transfer",
"other",
] as const satisfies readonly OperationCategory[];
function brokerageOperationsQueryOptions(
accountId: string | undefined,
query: BrokerageOperationsQuery = {},
) {
return apiQueryClient.queryOptions(
"get",
"/api/v1/brokerage-accounts/{accountId}/operations",
{
params: {
path: { accountId: accountId ?? "" },
query: brokerageOperationsQueryParameters(query),
},
},
);
}
function brokerageOperationsQueryParameters(query: BrokerageOperationsQuery) {
return {
...(query.instrumentUid && { instrumentUid: query.instrumentUid }),
...(query.from && { from: query.from }),
...(query.to && { to: query.to }),
...(query.categories?.length && { categories: query.categories.toSorted((left, right) => left.localeCompare(right)) }),
...(query.cursor && { cursor: query.cursor }),
...(query.limit && { limit: query.limit }),
};
}
function useBrokerageOperations(
accountId: string | undefined,
query: BrokerageOperationsQuery = {},
) {
return useResourceQuery({
meta: { accessGroup: "brokerage" },
...brokerageOperationsQueryOptions(accountId, query),
enabled: Boolean(accountId),
staleTime: 30_000,
});
}
export {
type BrokerageOperation,
brokerageOperationsQueryOptions,
brokerageOperationsQueryParameters as brokerageOperationsQueryParams,
operationCategories,
type OperationCategory,
useBrokerageOperations,
};