feat: deals table
This commit is contained in:
@ -1,6 +1,11 @@
|
||||
// This file is auto-generated by @hey-api/openapi-ts
|
||||
|
||||
import { queryOptions, type UseMutationOptions } from "@tanstack/react-query";
|
||||
import {
|
||||
infiniteQueryOptions,
|
||||
queryOptions,
|
||||
type InfiniteData,
|
||||
type UseMutationOptions,
|
||||
} from "@tanstack/react-query";
|
||||
import type { AxiosError } from "axios";
|
||||
import { client as _heyApiClient } from "../client.gen";
|
||||
import {
|
||||
@ -49,6 +54,8 @@ import type {
|
||||
DeleteStatusResponse2,
|
||||
GetBoardsData,
|
||||
GetDealsData,
|
||||
GetDealsError,
|
||||
GetDealsResponse2,
|
||||
GetProjectsData,
|
||||
GetStatusesData,
|
||||
UpdateBoardData,
|
||||
@ -224,13 +231,13 @@ export const updateBoardMutation = (
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
export const getDealsQueryKey = (options: Options<GetDealsData>) =>
|
||||
export const getDealsQueryKey = (options?: Options<GetDealsData>) =>
|
||||
createQueryKey("getDeals", options);
|
||||
|
||||
/**
|
||||
* Get Deals
|
||||
*/
|
||||
export const getDealsOptions = (options: Options<GetDealsData>) => {
|
||||
export const getDealsOptions = (options?: Options<GetDealsData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await getDeals({
|
||||
@ -245,6 +252,91 @@ export const getDealsOptions = (options: Options<GetDealsData>) => {
|
||||
});
|
||||
};
|
||||
|
||||
const createInfiniteParams = <
|
||||
K extends Pick<QueryKey<Options>[0], "body" | "headers" | "path" | "query">,
|
||||
>(
|
||||
queryKey: QueryKey<Options>,
|
||||
page: K
|
||||
) => {
|
||||
const params = {
|
||||
...queryKey[0],
|
||||
};
|
||||
if (page.body) {
|
||||
params.body = {
|
||||
...(queryKey[0].body as any),
|
||||
...(page.body as any),
|
||||
};
|
||||
}
|
||||
if (page.headers) {
|
||||
params.headers = {
|
||||
...queryKey[0].headers,
|
||||
...page.headers,
|
||||
};
|
||||
}
|
||||
if (page.path) {
|
||||
params.path = {
|
||||
...(queryKey[0].path as any),
|
||||
...(page.path as any),
|
||||
};
|
||||
}
|
||||
if (page.query) {
|
||||
params.query = {
|
||||
...(queryKey[0].query as any),
|
||||
...(page.query as any),
|
||||
};
|
||||
}
|
||||
return params as unknown as typeof page;
|
||||
};
|
||||
|
||||
export const getDealsInfiniteQueryKey = (
|
||||
options?: Options<GetDealsData>
|
||||
): QueryKey<Options<GetDealsData>> => createQueryKey("getDeals", options, true);
|
||||
|
||||
/**
|
||||
* Get Deals
|
||||
*/
|
||||
export const getDealsInfiniteOptions = (options?: Options<GetDealsData>) => {
|
||||
return infiniteQueryOptions<
|
||||
GetDealsResponse2,
|
||||
AxiosError<GetDealsError>,
|
||||
InfiniteData<GetDealsResponse2>,
|
||||
QueryKey<Options<GetDealsData>>,
|
||||
| number
|
||||
| null
|
||||
| Pick<
|
||||
QueryKey<Options<GetDealsData>>[0],
|
||||
"body" | "headers" | "path" | "query"
|
||||
>
|
||||
>(
|
||||
// @ts-ignore
|
||||
{
|
||||
queryFn: async ({ pageParam, queryKey, signal }) => {
|
||||
// @ts-ignore
|
||||
const page: Pick<
|
||||
QueryKey<Options<GetDealsData>>[0],
|
||||
"body" | "headers" | "path" | "query"
|
||||
> =
|
||||
typeof pageParam === "object"
|
||||
? pageParam
|
||||
: {
|
||||
query: {
|
||||
page: pageParam,
|
||||
},
|
||||
};
|
||||
const params = createInfiniteParams(queryKey, page);
|
||||
const { data } = await getDeals({
|
||||
...options,
|
||||
...params,
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: getDealsInfiniteQueryKey(options),
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const createDealQueryKey = (options: Options<CreateDealData>) =>
|
||||
createQueryKey("createDeal", options);
|
||||
|
||||
|
||||
@ -207,9 +207,9 @@ export const updateBoard = <ThrowOnError extends boolean = false>(
|
||||
* Get Deals
|
||||
*/
|
||||
export const getDeals = <ThrowOnError extends boolean = false>(
|
||||
options: Options<GetDealsData, ThrowOnError>
|
||||
options?: Options<GetDealsData, ThrowOnError>
|
||||
) => {
|
||||
return (options.client ?? _heyApiClient).get<
|
||||
return (options?.client ?? _heyApiClient).get<
|
||||
GetDealsResponses,
|
||||
GetDealsErrors,
|
||||
ThrowOnError
|
||||
@ -221,7 +221,7 @@ export const getDeals = <ThrowOnError extends boolean = false>(
|
||||
responseValidator: async data => {
|
||||
return await zGetDealsResponse2.parseAsync(data);
|
||||
},
|
||||
url: "/deal/{boardId}",
|
||||
url: "/deal/",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
@ -242,6 +242,7 @@ export type GetDealsResponse = {
|
||||
* Deals
|
||||
*/
|
||||
deals: Array<DealSchema>;
|
||||
paginationInfo: PaginationInfoSchema;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -274,6 +275,20 @@ export type HttpValidationError = {
|
||||
detail?: Array<ValidationError>;
|
||||
};
|
||||
|
||||
/**
|
||||
* PaginationInfoSchema
|
||||
*/
|
||||
export type PaginationInfoSchema = {
|
||||
/**
|
||||
* Totalpages
|
||||
*/
|
||||
totalPages: number;
|
||||
/**
|
||||
* Totalitems
|
||||
*/
|
||||
totalItems: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* ProjectSchema
|
||||
*/
|
||||
@ -568,14 +583,26 @@ export type UpdateBoardResponse2 =
|
||||
|
||||
export type GetDealsData = {
|
||||
body?: never;
|
||||
path: {
|
||||
path?: never;
|
||||
query?: {
|
||||
/**
|
||||
* Boardid
|
||||
*/
|
||||
boardId: number;
|
||||
boardId?: number | null;
|
||||
/**
|
||||
* Projectid
|
||||
*/
|
||||
projectId?: number | null;
|
||||
/**
|
||||
* Page
|
||||
*/
|
||||
page?: number | null;
|
||||
/**
|
||||
* Itemsperpage
|
||||
*/
|
||||
itemsPerPage?: number | null;
|
||||
};
|
||||
query?: never;
|
||||
url: "/deal/{boardId}";
|
||||
url: "/deal/";
|
||||
};
|
||||
|
||||
export type GetDealsErrors = {
|
||||
|
||||
@ -171,11 +171,20 @@ export const zGetBoardsResponse = z.object({
|
||||
boards: z.array(zBoardSchema),
|
||||
});
|
||||
|
||||
/**
|
||||
* PaginationInfoSchema
|
||||
*/
|
||||
export const zPaginationInfoSchema = z.object({
|
||||
totalPages: z.int(),
|
||||
totalItems: z.int(),
|
||||
});
|
||||
|
||||
/**
|
||||
* GetDealsResponse
|
||||
*/
|
||||
export const zGetDealsResponse = z.object({
|
||||
deals: z.array(zDealSchema),
|
||||
paginationInfo: zPaginationInfoSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
@ -348,10 +357,15 @@ export const zUpdateBoardResponse2 = zUpdateBoardResponse;
|
||||
|
||||
export const zGetDealsData = z.object({
|
||||
body: z.optional(z.never()),
|
||||
path: z.object({
|
||||
boardId: z.int(),
|
||||
}),
|
||||
query: z.optional(z.never()),
|
||||
path: z.optional(z.never()),
|
||||
query: z.optional(
|
||||
z.object({
|
||||
boardId: z.optional(z.union([z.int(), z.null()])),
|
||||
projectId: z.optional(z.union([z.int(), z.null()])),
|
||||
page: z.optional(z.union([z.int(), z.null()])),
|
||||
itemsPerPage: z.optional(z.union([z.int(), z.null()])),
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user