Yuki Takei 6 лет назад
Родитель
Сommit
cb13dcc999
1 измененных файлов с 17 добавлено и 17 удалено
  1. 17 17
      src/client/js/services/AppContainer.js

+ 17 - 17
src/client/js/services/AppContainer.js

@@ -67,6 +67,7 @@ export default class AppContainer extends Container {
     this.fetchUsers = this.fetchUsers.bind(this);
     this.fetchUsers = this.fetchUsers.bind(this);
     this.apiGet = this.apiGet.bind(this);
     this.apiGet = this.apiGet.bind(this);
     this.apiPost = this.apiPost.bind(this);
     this.apiPost = this.apiPost.bind(this);
+    this.apiDelete = this.apiDelete.bind(this);
     this.apiRequest = this.apiRequest.bind(this);
     this.apiRequest = this.apiRequest.bind(this);
   }
   }
 
 
@@ -278,11 +279,11 @@ export default class AppContainer extends Container {
     targetComponent.launchHandsontableModal(beginLineNumber, endLineNumber);
     targetComponent.launchHandsontableModal(beginLineNumber, endLineNumber);
   }
   }
 
 
-  apiGet(path, params) {
+  async apiGet(path, params) {
     return this.apiRequest('get', path, { params });
     return this.apiRequest('get', path, { params });
   }
   }
 
 
-  apiPost(path, params) {
+  async apiPost(path, params) {
     if (!params._csrf) {
     if (!params._csrf) {
       params._csrf = this.csrfToken;
       params._csrf = this.csrfToken;
     }
     }
@@ -290,21 +291,20 @@ export default class AppContainer extends Container {
     return this.apiRequest('post', path, params);
     return this.apiRequest('post', path, params);
   }
   }
 
 
-  apiRequest(method, path, params) {
-    return new Promise((resolve, reject) => {
-      axios[method](`/_api${path}`, params)
-        .then((res) => {
-          if (res.data.ok) {
-            resolve(res.data);
-          }
-          else {
-            reject(new Error(res.data.error));
-          }
-        })
-        .catch((res) => {
-          reject(res);
-        });
-    });
+  async apiDelete(path, params) {
+    if (!params._csrf) {
+      params._csrf = this.csrfToken;
+    }
+
+    return this.apiRequest('delete', path, { data: params });
+  }
+
+  async apiRequest(method, path, params) {
+    const res = await axios[method](`/_api${path}`, params);
+    if (res.data.ok) {
+      return res.data;
+    }
+    throw new Error(res.data.error);
   }
   }
 
 
 }
 }