feat: modules creation
This commit is contained in:
@ -24,6 +24,7 @@ import {
|
||||
createDealService,
|
||||
createDealTag,
|
||||
createMarketplace,
|
||||
createModule,
|
||||
createProduct,
|
||||
createProject,
|
||||
createService,
|
||||
@ -144,6 +145,9 @@ import type {
|
||||
CreateMarketplaceData,
|
||||
CreateMarketplaceError,
|
||||
CreateMarketplaceResponse2,
|
||||
CreateModuleData,
|
||||
CreateModuleError,
|
||||
CreateModuleResponse2,
|
||||
CreateProductData,
|
||||
CreateProductError,
|
||||
CreateProductResponse2,
|
||||
@ -1295,6 +1299,54 @@ export const getModulesOptions = (options?: Options<GetModulesData>) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const createModuleQueryKey = (options: Options<CreateModuleData>) =>
|
||||
createQueryKey("createModule", options);
|
||||
|
||||
/**
|
||||
* Create Module
|
||||
*/
|
||||
export const createModuleOptions = (options: Options<CreateModuleData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await createModule({
|
||||
...options,
|
||||
...queryKey[0],
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: createModuleQueryKey(options),
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create Module
|
||||
*/
|
||||
export const createModuleMutation = (
|
||||
options?: Partial<Options<CreateModuleData>>
|
||||
): UseMutationOptions<
|
||||
CreateModuleResponse2,
|
||||
AxiosError<CreateModuleError>,
|
||||
Options<CreateModuleData>
|
||||
> => {
|
||||
const mutationOptions: UseMutationOptions<
|
||||
CreateModuleResponse2,
|
||||
AxiosError<CreateModuleError>,
|
||||
Options<CreateModuleData>
|
||||
> = {
|
||||
mutationFn: async localOptions => {
|
||||
const { data } = await createModule({
|
||||
...options,
|
||||
...localOptions,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
};
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
export const getModulesWithAttributesQueryKey = (
|
||||
options?: Options<GetModulesWithAttributesData>
|
||||
) => createQueryKey("getModulesWithAttributes", options);
|
||||
|
||||
@ -50,6 +50,9 @@ import type {
|
||||
CreateMarketplaceData,
|
||||
CreateMarketplaceErrors,
|
||||
CreateMarketplaceResponses,
|
||||
CreateModuleData,
|
||||
CreateModuleErrors,
|
||||
CreateModuleResponses,
|
||||
CreateProductData,
|
||||
CreateProductErrors,
|
||||
CreateProductResponses,
|
||||
@ -292,6 +295,8 @@ import {
|
||||
zCreateDealTagResponse2,
|
||||
zCreateMarketplaceData,
|
||||
zCreateMarketplaceResponse2,
|
||||
zCreateModuleData,
|
||||
zCreateModuleResponse2,
|
||||
zCreateProductData,
|
||||
zCreateProductResponse2,
|
||||
zCreateProjectData,
|
||||
@ -1088,6 +1093,33 @@ export const getModules = <ThrowOnError extends boolean = false>(
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create Module
|
||||
*/
|
||||
export const createModule = <ThrowOnError extends boolean = false>(
|
||||
options: Options<CreateModuleData, ThrowOnError>
|
||||
) => {
|
||||
return (options.client ?? _heyApiClient).post<
|
||||
CreateModuleResponses,
|
||||
CreateModuleErrors,
|
||||
ThrowOnError
|
||||
>({
|
||||
requestValidator: async data => {
|
||||
return await zCreateModuleData.parseAsync(data);
|
||||
},
|
||||
responseType: "json",
|
||||
responseValidator: async data => {
|
||||
return await zCreateModuleResponse2.parseAsync(data);
|
||||
},
|
||||
url: "/crm/v1/module/",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Modules With Attributes
|
||||
*/
|
||||
|
||||
@ -660,6 +660,37 @@ export type CreateMarketplaceSchema = {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* CreateModuleRequest
|
||||
*/
|
||||
export type CreateModuleRequest = {
|
||||
entity: CreateModuleSchema;
|
||||
};
|
||||
|
||||
/**
|
||||
* CreateModuleResponse
|
||||
*/
|
||||
export type CreateModuleResponse = {
|
||||
/**
|
||||
* Message
|
||||
*/
|
||||
message: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* CreateModuleSchema
|
||||
*/
|
||||
export type CreateModuleSchema = {
|
||||
/**
|
||||
* Label
|
||||
*/
|
||||
label: string;
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
description: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* CreateProductRequest
|
||||
*/
|
||||
@ -1823,7 +1854,7 @@ export type ModuleTabSchema = {
|
||||
/**
|
||||
* Iconname
|
||||
*/
|
||||
iconName: string;
|
||||
iconName: string | null;
|
||||
/**
|
||||
* Device
|
||||
*/
|
||||
@ -3715,6 +3746,32 @@ export type GetModulesResponses = {
|
||||
|
||||
export type GetModulesResponse = GetModulesResponses[keyof GetModulesResponses];
|
||||
|
||||
export type CreateModuleData = {
|
||||
body: CreateModuleRequest;
|
||||
path?: never;
|
||||
query?: never;
|
||||
url: "/crm/v1/module/";
|
||||
};
|
||||
|
||||
export type CreateModuleErrors = {
|
||||
/**
|
||||
* Validation Error
|
||||
*/
|
||||
422: HttpValidationError;
|
||||
};
|
||||
|
||||
export type CreateModuleError = CreateModuleErrors[keyof CreateModuleErrors];
|
||||
|
||||
export type CreateModuleResponses = {
|
||||
/**
|
||||
* Successful Response
|
||||
*/
|
||||
200: CreateModuleResponse;
|
||||
};
|
||||
|
||||
export type CreateModuleResponse2 =
|
||||
CreateModuleResponses[keyof CreateModuleResponses];
|
||||
|
||||
export type GetModulesWithAttributesData = {
|
||||
body?: never;
|
||||
path?: never;
|
||||
|
||||
@ -559,6 +559,28 @@ export const zCreateMarketplaceResponse = z.object({
|
||||
entity: zMarketplaceSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
* CreateModuleSchema
|
||||
*/
|
||||
export const zCreateModuleSchema = z.object({
|
||||
label: z.string(),
|
||||
description: z.union([z.string(), z.null()]),
|
||||
});
|
||||
|
||||
/**
|
||||
* CreateModuleRequest
|
||||
*/
|
||||
export const zCreateModuleRequest = z.object({
|
||||
entity: zCreateModuleSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
* CreateModuleResponse
|
||||
*/
|
||||
export const zCreateModuleResponse = z.object({
|
||||
message: z.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* CreateProductSchema
|
||||
*/
|
||||
@ -637,7 +659,7 @@ export const zModuleTabSchema = z.object({
|
||||
id: z.int(),
|
||||
key: z.string(),
|
||||
label: z.string(),
|
||||
iconName: z.string(),
|
||||
iconName: z.union([z.string(), z.null()]),
|
||||
device: z.string(),
|
||||
});
|
||||
|
||||
@ -2058,6 +2080,17 @@ export const zGetModulesData = z.object({
|
||||
*/
|
||||
export const zGetModulesResponse = zGetAllModulesResponse;
|
||||
|
||||
export const zCreateModuleData = z.object({
|
||||
body: zCreateModuleRequest,
|
||||
path: z.optional(z.never()),
|
||||
query: z.optional(z.never()),
|
||||
});
|
||||
|
||||
/**
|
||||
* Successful Response
|
||||
*/
|
||||
export const zCreateModuleResponse2 = zCreateModuleResponse;
|
||||
|
||||
export const zGetModulesWithAttributesData = z.object({
|
||||
body: z.optional(z.never()),
|
||||
path: z.optional(z.never()),
|
||||
|
||||
Reference in New Issue
Block a user