All files / tcb-admin-node/src/database request.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 2/2
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  4x               4x                             34x                   21x       21x                    
import { Db } from "./db";
import * as requestHandler from "../utils/httpRequest";
 
/**
 * 数据库模块的通用请求方法
 *
 * @author haroldhu
 * @internal
 */
export class Request {
  /**
   * db 的实例
   *
   * @internal
   */
  private db: Db;
 
  /**
   * 初始化
   *
   * @internal
   * @param db
   */
  constructor(db: Db) {
    this.db = db;
  }
 
  /**
   * 发送请求
   *
   * @param api   - 接口
   * @param data  - 参数
   */
  send(api?: string, data?: Object): Promise<any> {
    const params = Object.assign({}, data, {
      action: `database.${api}`
    });
    // console.log(this.db.config.config);
    return requestHandler({
      config: this.db.config.config,
      params,
      method: "post",
      headers: {
        "content-type": "application/json"
      }
    });
  }
}