Просмотр исходного кода

Removed old base api and added patch method

jnfrati 4 лет назад
Родитель
Сommit
d3143f2776
2 измененных файлов с 9 добавлено и 38 удалено
  1. 9 0
      dashboard/src/shared/baseApi.ts
  2. 0 38
      dashboard/src/shared/baseApi.tsx

+ 9 - 0
dashboard/src/shared/baseApi.ts

@@ -64,6 +64,15 @@ const buildAxiosConfig: BuildAxiosConfigFunction = (
     };
   }
 
+  if (method.toUpperCase() === "PATCH") {
+    return {
+      ...config,
+      params: params,
+      paramsSerializer: (params) =>
+        qs.stringify(params, { arrayFormat: "repeat" }),
+    };
+  }
+
   return config;
 };
 

+ 0 - 38
dashboard/src/shared/baseApi.tsx

@@ -1,38 +0,0 @@
-import axios from "axios";
-import qs from "qs";
-
-// axios.defaults.timeout = 10000;
-
-// Partial function that accepts a generic params type and returns an api method
-export const baseApi = <T extends {}, S = {}>(
-  requestType: string,
-  endpoint: ((pathParams: S) => string) | string
-) => {
-  return (token: string, params: T, pathParams: S) => {
-    // Generate endpoint literal
-    let endpointString: ((pathParams: S) => string) | string;
-    if (typeof endpoint === "string") {
-      endpointString = endpoint;
-    } else {
-      endpointString = endpoint(pathParams);
-    }
-
-    // Handle request type (can refactor)
-    if (requestType === "POST") {
-      return axios.post(endpointString, params, {});
-    } else if (requestType === "PUT") {
-      return axios.put(endpointString, params, {});
-    } else if (requestType === "DELETE") {
-      return axios.delete(
-        endpointString + "?" + qs.stringify(params, { arrayFormat: "repeat" })
-      );
-    } else {
-      return axios.get(endpointString, {
-        params,
-        paramsSerializer: function (params) {
-          return qs.stringify(params, { arrayFormat: "repeat" });
-        },
-      });
-    }
-  };
-};