85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
// This file is auto-generated by @hey-api/openapi-ts
|
|
|
|
import { queryOptions } from "@tanstack/react-query";
|
|
import { client as _heyApiClient } from "../client.gen";
|
|
import { getBoards, getProjects, type Options } from "../sdk.gen";
|
|
import type { GetBoardsData, GetProjectsData } from "../types.gen";
|
|
|
|
export type QueryKey<TOptions extends Options> = [
|
|
Pick<TOptions, "baseURL" | "body" | "headers" | "path" | "query"> & {
|
|
_id: string;
|
|
_infinite?: boolean;
|
|
},
|
|
];
|
|
|
|
const createQueryKey = <TOptions extends Options>(
|
|
id: string,
|
|
options?: TOptions,
|
|
infinite?: boolean
|
|
): [QueryKey<TOptions>[0]] => {
|
|
const params: QueryKey<TOptions>[0] = {
|
|
_id: id,
|
|
baseURL:
|
|
options?.baseURL ||
|
|
(options?.client ?? _heyApiClient).getConfig().baseURL,
|
|
} as QueryKey<TOptions>[0];
|
|
if (infinite) {
|
|
params._infinite = infinite;
|
|
}
|
|
if (options?.body) {
|
|
params.body = options.body;
|
|
}
|
|
if (options?.headers) {
|
|
params.headers = options.headers;
|
|
}
|
|
if (options?.path) {
|
|
params.path = options.path;
|
|
}
|
|
if (options?.query) {
|
|
params.query = options.query;
|
|
}
|
|
return [params];
|
|
};
|
|
|
|
export const getProjectsQueryKey = (options?: Options<GetProjectsData>) =>
|
|
createQueryKey("getProjects", options);
|
|
|
|
/**
|
|
* Get Projects
|
|
*/
|
|
export const getProjectsOptions = (options?: Options<GetProjectsData>) => {
|
|
return queryOptions({
|
|
queryFn: async ({ queryKey, signal }) => {
|
|
const { data } = await getProjects({
|
|
...options,
|
|
...queryKey[0],
|
|
signal,
|
|
throwOnError: true,
|
|
});
|
|
return data;
|
|
},
|
|
queryKey: getProjectsQueryKey(options),
|
|
});
|
|
};
|
|
|
|
export const getBoardsQueryKey = (options: Options<GetBoardsData>) =>
|
|
createQueryKey("getBoards", options);
|
|
|
|
/**
|
|
* Get Boards
|
|
*/
|
|
export const getBoardsOptions = (options: Options<GetBoardsData>) => {
|
|
return queryOptions({
|
|
queryFn: async ({ queryKey, signal }) => {
|
|
const { data } = await getBoards({
|
|
...options,
|
|
...queryKey[0],
|
|
signal,
|
|
throwOnError: true,
|
|
});
|
|
return data;
|
|
},
|
|
queryKey: getBoardsQueryKey(options),
|
|
});
|
|
};
|