浏览代码

ajout de params type metadata pour nos request

Vincent GUFFON 4 年之前
父节点
当前提交
582366df73
共有 1 个文件被更改,包括 25 次插入15 次删除
  1. 25 15
      services/connection/connection.ts

+ 25 - 15
services/connection/connection.ts

@@ -32,9 +32,9 @@ class Connection {
     switch (method) {
       case HTTP_METHOD.GET:
         if (args.id) {
-          return Connection.getItem(url, args.id, args.showProgress)
+          return Connection.getItem(url, args.id, args.showProgress, args.params)
         } else {
-          return Connection.getCollection(url, args.showProgress, args.type)
+          return Connection.getCollection(url, args.type, args.showProgress, args.params)
         }
 
       case HTTP_METHOD.PUT:
@@ -45,11 +45,11 @@ class Connection {
         if (!args.data) {
           throw new Error('*args* has no data')
         }
-        return method === HTTP_METHOD.PUT ? Connection.put(url, args.id, args.data, args.showProgress) :
-                                            Connection.post(url, args.data, args.showProgress)
+        return method === HTTP_METHOD.PUT ? Connection.put(url, args.id, args.data, args.showProgress, args.params) :
+                                            Connection.post(url, args.data, args.showProgress, args.params)
 
       case HTTP_METHOD.DELETE:
-        return Connection.deleteItem(url, args.id, args.showProgress)
+        return Connection.deleteItem(url, args.id, args.showProgress, args.params)
     }
 
     throw new Error('Unknown connection method was invoked')
@@ -60,13 +60,15 @@ class Connection {
    * @param {string} url
    * @param {number} id
    * @param {boolean} showProgress
+   * @param {AnyJson} params
    * @return {Promise<any>}
    */
-  public static getItem (url: string, id: number, showProgress: boolean = true): Promise<any> {
+  public static getItem (url: string, id: number, showProgress: boolean = true, params: AnyJson = {}): Promise<any> {
     const config: AxiosRequestConfig = {
       url: `${url}/${id}`,
       method: HTTP_METHOD.GET,
-      progress: showProgress
+      progress: showProgress,
+      params: params
     }
     return Connection.request(config)
   }
@@ -76,13 +78,15 @@ class Connection {
    * @param {string} url
    * @param {boolean} progress
    * @param {QUERY_TYPE} type
+   * @param {AnyJson} params
    * @return {Promise<any>}
    */
-  public static getCollection (url: string, progress: boolean = true, type: QUERY_TYPE): Promise<any> {
+  public static getCollection (url: string, type: QUERY_TYPE, progress: boolean = true, params: AnyJson = {}): Promise<any> {
     let config: AxiosRequestConfig = {
       url: `${url}`,
       method: HTTP_METHOD.GET,
-      progress
+      progress,
+      params: params
     }
     if(type === QUERY_TYPE.IMAGE)
       config = {...config, responseType: 'blob'}
@@ -95,14 +99,16 @@ class Connection {
    * @param {string} url
    * @param {AnyJson} data
    * @param {boolean} progress
+   * @param {AnyJson} params
    * @return {Promise<any>}
    */
-  public static post (url: string, data: AnyJson, progress: boolean = true): Promise<any> {
+  public static post (url: string, data: AnyJson, progress: boolean = true, params: AnyJson = {}): Promise<any> {
     const config: AxiosRequestConfig = {
       url: `${url}`,
       method: HTTP_METHOD.POST,
       data,
-      progress
+      progress,
+      params: params
     }
     return Connection.request(config)
   }
@@ -113,14 +119,16 @@ class Connection {
    * @param {number} id
    * @param {AnyJson} data
    * @param {boolean} progress
+   * @param {AnyJson} params
    * @return {Promise<any>}
    */
-  public static put (url: string, id: number, data: AnyJson, progress: boolean = true): Promise<any> {
+  public static put (url: string, id: number, data: AnyJson, progress: boolean = true, params: AnyJson = {}): Promise<any> {
     const config: AxiosRequestConfig = {
       url: `${url}/${id}`,
       method: HTTP_METHOD.PUT,
       data,
-      progress
+      progress,
+      params: params
     }
     return Connection.request(config)
   }
@@ -130,13 +138,15 @@ class Connection {
    * @param {string} url
    * @param {number} id
    * @param {boolean} progress
+   * @param {AnyJson} params
    * @return {Promise<any>}
    */
-  public static deleteItem (url: string, id: number, progress: boolean = true): Promise<any> {
+  public static deleteItem (url: string, id: number, progress: boolean = true, params: AnyJson = {}): Promise<any> {
     const config: AxiosRequestConfig = {
       url: `${url}/${id}`,
       method: HTTP_METHOD.DELETE,
-      progress
+      progress,
+      params: params
     }
     return Connection.request(config)
   }