feat: deal create, update, delete
This commit is contained in:
@ -5,9 +5,11 @@ import type { AxiosError } from "axios";
|
||||
import { client as _heyApiClient } from "../client.gen";
|
||||
import {
|
||||
createBoard,
|
||||
createDeal,
|
||||
createProject,
|
||||
createStatus,
|
||||
deleteBoard,
|
||||
deleteDeal,
|
||||
deleteProject,
|
||||
deleteStatus,
|
||||
getBoards,
|
||||
@ -24,6 +26,9 @@ import type {
|
||||
CreateBoardData,
|
||||
CreateBoardError,
|
||||
CreateBoardResponse2,
|
||||
CreateDealData,
|
||||
CreateDealError,
|
||||
CreateDealResponse2,
|
||||
CreateProjectData,
|
||||
CreateProjectError,
|
||||
CreateProjectResponse2,
|
||||
@ -33,6 +38,9 @@ import type {
|
||||
DeleteBoardData,
|
||||
DeleteBoardError,
|
||||
DeleteBoardResponse2,
|
||||
DeleteDealData,
|
||||
DeleteDealError,
|
||||
DeleteDealResponse2,
|
||||
DeleteProjectData,
|
||||
DeleteProjectError,
|
||||
DeleteProjectResponse2,
|
||||
@ -237,6 +245,81 @@ export const getDealsOptions = (options: Options<GetDealsData>) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const createDealQueryKey = (options: Options<CreateDealData>) =>
|
||||
createQueryKey("createDeal", options);
|
||||
|
||||
/**
|
||||
* Create Deal
|
||||
*/
|
||||
export const createDealOptions = (options: Options<CreateDealData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await createDeal({
|
||||
...options,
|
||||
...queryKey[0],
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: createDealQueryKey(options),
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create Deal
|
||||
*/
|
||||
export const createDealMutation = (
|
||||
options?: Partial<Options<CreateDealData>>
|
||||
): UseMutationOptions<
|
||||
CreateDealResponse2,
|
||||
AxiosError<CreateDealError>,
|
||||
Options<CreateDealData>
|
||||
> => {
|
||||
const mutationOptions: UseMutationOptions<
|
||||
CreateDealResponse2,
|
||||
AxiosError<CreateDealError>,
|
||||
Options<CreateDealData>
|
||||
> = {
|
||||
mutationFn: async localOptions => {
|
||||
const { data } = await createDeal({
|
||||
...options,
|
||||
...localOptions,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
};
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete Deal
|
||||
*/
|
||||
export const deleteDealMutation = (
|
||||
options?: Partial<Options<DeleteDealData>>
|
||||
): UseMutationOptions<
|
||||
DeleteDealResponse2,
|
||||
AxiosError<DeleteDealError>,
|
||||
Options<DeleteDealData>
|
||||
> => {
|
||||
const mutationOptions: UseMutationOptions<
|
||||
DeleteDealResponse2,
|
||||
AxiosError<DeleteDealError>,
|
||||
Options<DeleteDealData>
|
||||
> = {
|
||||
mutationFn: async localOptions => {
|
||||
const { data } = await deleteDeal({
|
||||
...options,
|
||||
...localOptions,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
};
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Deal
|
||||
*/
|
||||
|
||||
@ -6,6 +6,9 @@ import type {
|
||||
CreateBoardData,
|
||||
CreateBoardErrors,
|
||||
CreateBoardResponses,
|
||||
CreateDealData,
|
||||
CreateDealErrors,
|
||||
CreateDealResponses,
|
||||
CreateProjectData,
|
||||
CreateProjectErrors,
|
||||
CreateProjectResponses,
|
||||
@ -15,6 +18,9 @@ import type {
|
||||
DeleteBoardData,
|
||||
DeleteBoardErrors,
|
||||
DeleteBoardResponses,
|
||||
DeleteDealData,
|
||||
DeleteDealErrors,
|
||||
DeleteDealResponses,
|
||||
DeleteProjectData,
|
||||
DeleteProjectErrors,
|
||||
DeleteProjectResponses,
|
||||
@ -48,12 +54,16 @@ import type {
|
||||
import {
|
||||
zCreateBoardData,
|
||||
zCreateBoardResponse2,
|
||||
zCreateDealData,
|
||||
zCreateDealResponse2,
|
||||
zCreateProjectData,
|
||||
zCreateProjectResponse2,
|
||||
zCreateStatusData,
|
||||
zCreateStatusResponse2,
|
||||
zDeleteBoardData,
|
||||
zDeleteBoardResponse2,
|
||||
zDeleteDealData,
|
||||
zDeleteDealResponse2,
|
||||
zDeleteProjectData,
|
||||
zDeleteProjectResponse2,
|
||||
zDeleteStatusData,
|
||||
@ -216,6 +226,56 @@ export const getDeals = <ThrowOnError extends boolean = false>(
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create Deal
|
||||
*/
|
||||
export const createDeal = <ThrowOnError extends boolean = false>(
|
||||
options: Options<CreateDealData, ThrowOnError>
|
||||
) => {
|
||||
return (options.client ?? _heyApiClient).post<
|
||||
CreateDealResponses,
|
||||
CreateDealErrors,
|
||||
ThrowOnError
|
||||
>({
|
||||
requestValidator: async data => {
|
||||
return await zCreateDealData.parseAsync(data);
|
||||
},
|
||||
responseType: "json",
|
||||
responseValidator: async data => {
|
||||
return await zCreateDealResponse2.parseAsync(data);
|
||||
},
|
||||
url: "/deal/",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete Deal
|
||||
*/
|
||||
export const deleteDeal = <ThrowOnError extends boolean = false>(
|
||||
options: Options<DeleteDealData, ThrowOnError>
|
||||
) => {
|
||||
return (options.client ?? _heyApiClient).delete<
|
||||
DeleteDealResponses,
|
||||
DeleteDealErrors,
|
||||
ThrowOnError
|
||||
>({
|
||||
requestValidator: async data => {
|
||||
return await zDeleteDealData.parseAsync(data);
|
||||
},
|
||||
responseType: "json",
|
||||
responseValidator: async data => {
|
||||
return await zDeleteDealResponse2.parseAsync(data);
|
||||
},
|
||||
url: "/deal/{pk}",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Deal
|
||||
*/
|
||||
@ -234,7 +294,7 @@ export const updateDeal = <ThrowOnError extends boolean = false>(
|
||||
responseValidator: async data => {
|
||||
return await zUpdateDealResponse2.parseAsync(data);
|
||||
},
|
||||
url: "/deal/{dealId}",
|
||||
url: "/deal/{pk}",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@ -54,6 +54,46 @@ export type CreateBoardSchema = {
|
||||
lexorank: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* CreateDealRequest
|
||||
*/
|
||||
export type CreateDealRequest = {
|
||||
entity: CreateDealSchema;
|
||||
};
|
||||
|
||||
/**
|
||||
* CreateDealResponse
|
||||
*/
|
||||
export type CreateDealResponse = {
|
||||
/**
|
||||
* Message
|
||||
*/
|
||||
message: string;
|
||||
entity: DealSchema;
|
||||
};
|
||||
|
||||
/**
|
||||
* CreateDealSchema
|
||||
*/
|
||||
export type CreateDealSchema = {
|
||||
/**
|
||||
* Name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Boardid
|
||||
*/
|
||||
boardId: number;
|
||||
/**
|
||||
* Lexorank
|
||||
*/
|
||||
lexorank: string;
|
||||
/**
|
||||
* Statusid
|
||||
*/
|
||||
statusId: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* CreateProjectRequest
|
||||
*/
|
||||
@ -122,14 +162,14 @@ export type CreateStatusSchema = {
|
||||
* DealSchema
|
||||
*/
|
||||
export type DealSchema = {
|
||||
/**
|
||||
* Name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Id
|
||||
*/
|
||||
id: number;
|
||||
/**
|
||||
* Name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Lexorank
|
||||
*/
|
||||
@ -150,6 +190,16 @@ export type DeleteBoardResponse = {
|
||||
message: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* DeleteDealResponse
|
||||
*/
|
||||
export type DeleteDealResponse = {
|
||||
/**
|
||||
* Message
|
||||
*/
|
||||
message: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* DeleteProjectResponse
|
||||
*/
|
||||
@ -287,7 +337,7 @@ export type UpdateBoardSchema = {
|
||||
* UpdateDealRequest
|
||||
*/
|
||||
export type UpdateDealRequest = {
|
||||
deal: UpdateDealSchema;
|
||||
entity: UpdateDealSchema;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -542,16 +592,73 @@ export type GetDealsResponses = {
|
||||
|
||||
export type GetDealsResponse2 = GetDealsResponses[keyof GetDealsResponses];
|
||||
|
||||
export type CreateDealData = {
|
||||
body: CreateDealRequest;
|
||||
path?: never;
|
||||
query?: never;
|
||||
url: "/deal/";
|
||||
};
|
||||
|
||||
export type CreateDealErrors = {
|
||||
/**
|
||||
* Validation Error
|
||||
*/
|
||||
422: HttpValidationError;
|
||||
};
|
||||
|
||||
export type CreateDealError = CreateDealErrors[keyof CreateDealErrors];
|
||||
|
||||
export type CreateDealResponses = {
|
||||
/**
|
||||
* Successful Response
|
||||
*/
|
||||
200: CreateDealResponse;
|
||||
};
|
||||
|
||||
export type CreateDealResponse2 =
|
||||
CreateDealResponses[keyof CreateDealResponses];
|
||||
|
||||
export type DeleteDealData = {
|
||||
body?: never;
|
||||
path: {
|
||||
/**
|
||||
* Pk
|
||||
*/
|
||||
pk: number;
|
||||
};
|
||||
query?: never;
|
||||
url: "/deal/{pk}";
|
||||
};
|
||||
|
||||
export type DeleteDealErrors = {
|
||||
/**
|
||||
* Validation Error
|
||||
*/
|
||||
422: HttpValidationError;
|
||||
};
|
||||
|
||||
export type DeleteDealError = DeleteDealErrors[keyof DeleteDealErrors];
|
||||
|
||||
export type DeleteDealResponses = {
|
||||
/**
|
||||
* Successful Response
|
||||
*/
|
||||
200: DeleteDealResponse;
|
||||
};
|
||||
|
||||
export type DeleteDealResponse2 =
|
||||
DeleteDealResponses[keyof DeleteDealResponses];
|
||||
|
||||
export type UpdateDealData = {
|
||||
body: UpdateDealRequest;
|
||||
path: {
|
||||
/**
|
||||
* Dealid
|
||||
* Pk
|
||||
*/
|
||||
dealId: number;
|
||||
pk: number;
|
||||
};
|
||||
query?: never;
|
||||
url: "/deal/{dealId}";
|
||||
url: "/deal/{pk}";
|
||||
};
|
||||
|
||||
export type UpdateDealErrors = {
|
||||
|
||||
@ -35,6 +35,41 @@ export const zCreateBoardResponse = z.object({
|
||||
entity: zBoardSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
* CreateDealSchema
|
||||
*/
|
||||
export const zCreateDealSchema = z.object({
|
||||
name: z.string(),
|
||||
boardId: z.int(),
|
||||
lexorank: z.string(),
|
||||
statusId: z.int(),
|
||||
});
|
||||
|
||||
/**
|
||||
* CreateDealRequest
|
||||
*/
|
||||
export const zCreateDealRequest = z.object({
|
||||
entity: zCreateDealSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
* DealSchema
|
||||
*/
|
||||
export const zDealSchema = z.object({
|
||||
id: z.int(),
|
||||
name: z.string(),
|
||||
lexorank: z.string(),
|
||||
statusId: z.int(),
|
||||
});
|
||||
|
||||
/**
|
||||
* CreateDealResponse
|
||||
*/
|
||||
export const zCreateDealResponse = z.object({
|
||||
message: z.string(),
|
||||
entity: zDealSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
* CreateProjectSchema
|
||||
*/
|
||||
@ -98,16 +133,6 @@ export const zCreateStatusResponse = z.object({
|
||||
entity: zStatusSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
* DealSchema
|
||||
*/
|
||||
export const zDealSchema = z.object({
|
||||
name: z.string(),
|
||||
id: z.int(),
|
||||
lexorank: z.string(),
|
||||
statusId: z.int(),
|
||||
});
|
||||
|
||||
/**
|
||||
* DeleteBoardResponse
|
||||
*/
|
||||
@ -115,6 +140,13 @@ export const zDeleteBoardResponse = z.object({
|
||||
message: z.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* DeleteDealResponse
|
||||
*/
|
||||
export const zDeleteDealResponse = z.object({
|
||||
message: z.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* DeleteProjectResponse
|
||||
*/
|
||||
@ -208,7 +240,7 @@ export const zUpdateDealSchema = z.object({
|
||||
* UpdateDealRequest
|
||||
*/
|
||||
export const zUpdateDealRequest = z.object({
|
||||
deal: zUpdateDealSchema,
|
||||
entity: zUpdateDealSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
@ -324,10 +356,34 @@ export const zGetDealsData = z.object({
|
||||
*/
|
||||
export const zGetDealsResponse2 = zGetDealsResponse;
|
||||
|
||||
export const zCreateDealData = z.object({
|
||||
body: zCreateDealRequest,
|
||||
path: z.optional(z.never()),
|
||||
query: z.optional(z.never()),
|
||||
});
|
||||
|
||||
/**
|
||||
* Successful Response
|
||||
*/
|
||||
export const zCreateDealResponse2 = zCreateDealResponse;
|
||||
|
||||
export const zDeleteDealData = z.object({
|
||||
body: z.optional(z.never()),
|
||||
path: z.object({
|
||||
pk: z.int(),
|
||||
}),
|
||||
query: z.optional(z.never()),
|
||||
});
|
||||
|
||||
/**
|
||||
* Successful Response
|
||||
*/
|
||||
export const zDeleteDealResponse2 = zDeleteDealResponse;
|
||||
|
||||
export const zUpdateDealData = z.object({
|
||||
body: zUpdateDealRequest,
|
||||
path: z.object({
|
||||
dealId: z.int(),
|
||||
pk: z.int(),
|
||||
}),
|
||||
query: z.optional(z.never()),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user