pet.vuequery.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* eslint-disable */
  2. // @ts-ignore
  3. import { queryOptions, useMutation } from '@tanstack/vue-query';
  4. import type { DefaultError } from '@tanstack/vue-query';
  5. import request from '@/utils/request';
  6. import { CustomRequestOptions } from '@/interceptors/request';
  7. import * as apis from './pet';
  8. import * as API from './types';
  9. /** Update an existing pet PUT /pet */
  10. export function useUpdatePetMutation(options?: {
  11. onSuccess?: (value?: unknown) => void;
  12. onError?: (error?: DefaultError) => void;
  13. }) {
  14. const { onSuccess, onError } = options || {};
  15. const response = useMutation({
  16. mutationFn: apis.updatePet,
  17. onSuccess(data: unknown) {
  18. onSuccess?.(data);
  19. },
  20. onError(error) {
  21. onError?.(error);
  22. },
  23. });
  24. return response;
  25. }
  26. /** Add a new pet to the store POST /pet */
  27. export function useAddPetMutation(options?: {
  28. onSuccess?: (value?: unknown) => void;
  29. onError?: (error?: DefaultError) => void;
  30. }) {
  31. const { onSuccess, onError } = options || {};
  32. const response = useMutation({
  33. mutationFn: apis.addPet,
  34. onSuccess(data: unknown) {
  35. onSuccess?.(data);
  36. },
  37. onError(error) {
  38. onError?.(error);
  39. },
  40. });
  41. return response;
  42. }
  43. /** Find pet by ID Returns a single pet GET /pet/${param0} */
  44. export function getPetByIdQueryOptions(options: {
  45. // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  46. params: API.getPetByIdParams;
  47. options?: CustomRequestOptions;
  48. }) {
  49. return queryOptions({
  50. queryFn: async ({ queryKey }) => {
  51. return apis.getPetById(queryKey[1] as typeof options);
  52. },
  53. queryKey: ['getPetById', options],
  54. });
  55. }
  56. /** Updates a pet in the store with form data POST /pet/${param0} */
  57. export function useUpdatePetWithFormMutation(options?: {
  58. onSuccess?: (value?: unknown) => void;
  59. onError?: (error?: DefaultError) => void;
  60. }) {
  61. const { onSuccess, onError } = options || {};
  62. const response = useMutation({
  63. mutationFn: apis.updatePetWithForm,
  64. onSuccess(data: unknown) {
  65. onSuccess?.(data);
  66. },
  67. onError(error) {
  68. onError?.(error);
  69. },
  70. });
  71. return response;
  72. }
  73. /** Deletes a pet DELETE /pet/${param0} */
  74. export function useDeletePetMutation(options?: {
  75. onSuccess?: (value?: unknown) => void;
  76. onError?: (error?: DefaultError) => void;
  77. }) {
  78. const { onSuccess, onError } = options || {};
  79. const response = useMutation({
  80. mutationFn: apis.deletePet,
  81. onSuccess(data: unknown) {
  82. onSuccess?.(data);
  83. },
  84. onError(error) {
  85. onError?.(error);
  86. },
  87. });
  88. return response;
  89. }
  90. /** uploads an image POST /pet/${param0}/uploadImage */
  91. export function useUploadFileMutation(options?: {
  92. onSuccess?: (value?: API.ApiResponse) => void;
  93. onError?: (error?: DefaultError) => void;
  94. }) {
  95. const { onSuccess, onError } = options || {};
  96. const response = useMutation({
  97. mutationFn: apis.uploadFile,
  98. onSuccess(data: API.ApiResponse) {
  99. onSuccess?.(data);
  100. },
  101. onError(error) {
  102. onError?.(error);
  103. },
  104. });
  105. return response;
  106. }
  107. /** Finds Pets by status Multiple status values can be provided with comma separated strings GET /pet/findByStatus */
  108. export function findPetsByStatusQueryOptions(options: {
  109. // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  110. params: API.findPetsByStatusParams;
  111. options?: CustomRequestOptions;
  112. }) {
  113. return queryOptions({
  114. queryFn: async ({ queryKey }) => {
  115. return apis.findPetsByStatus(queryKey[1] as typeof options);
  116. },
  117. queryKey: ['findPetsByStatus', options],
  118. });
  119. }
  120. /** Finds Pets by tags Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. GET /pet/findByTags */
  121. export function findPetsByTagsQueryOptions(options: {
  122. // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  123. params: API.findPetsByTagsParams;
  124. options?: CustomRequestOptions;
  125. }) {
  126. return queryOptions({
  127. queryFn: async ({ queryKey }) => {
  128. return apis.findPetsByTags(queryKey[1] as typeof options);
  129. },
  130. queryKey: ['findPetsByTags', options],
  131. });
  132. }