generated from stijnvanhulle/template
-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea1ccc2
commit 03dc141
Showing
4 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
type CreatePetsClient = typeof client<CreatePetsMutationResponse, never, CreatePetsMutationRequest> | ||
type CreatePets = { | ||
data: CreatePetsMutationResponse | ||
error: never | ||
request: CreatePetsMutationRequest | ||
pathParams: CreatePetsPathParams | ||
queryParams: CreatePetsQueryParams | ||
headerParams: CreatePetsHeaderParams | ||
response: CreatePetsMutationResponse | ||
client: { | ||
parameters: Partial<Parameters<CreatePetsClient>[0]> | ||
return: Awaited<ReturnType<CreatePetsClient>> | ||
} | ||
} | ||
|
||
/** | ||
* @summary Create a pet | ||
* @link /pets/:uuid */ | ||
|
||
export function useCreatePets( | ||
options: { | ||
mutation?: UseMutationOptions< | ||
CreatePets['response'], | ||
CreatePets['error'], | ||
{ uuid: CreatePetsPathParams['uuid']; params?: CreatePets['queryParams']; headers: CreatePets['headerParams']; data: CreatePets['request'] } | ||
> | ||
client?: CreatePets['client']['parameters'] | ||
} = {}, | ||
): UseMutationResult< | ||
CreatePets['response'], | ||
CreatePets['error'], | ||
{ uuid: CreatePetsPathParams['uuid']; params?: CreatePets['queryParams']; headers: CreatePets['headerParams']; data: CreatePets['request'] } | ||
> { | ||
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} | ||
|
||
return useMutation< | ||
CreatePets['response'], | ||
CreatePets['error'], | ||
{ uuid: CreatePetsPathParams['uuid']; params?: CreatePets['queryParams']; headers: CreatePets['headerParams']; data: CreatePets['request'] } | ||
>({ | ||
mutationFn: async ({ uuid, headers, data, params }) => { | ||
const res = await client<CreatePets['data'], CreatePets['error'], CreatePets['request']>({ | ||
method: 'post', | ||
url: `/pets/${uuid}`, | ||
params, | ||
data, | ||
headers: { ...headers, ...clientOptions.headers }, | ||
...clientOptions, | ||
}) | ||
|
||
return res.data | ||
}, | ||
...mutationOptions, | ||
}) | ||
} |