lib/mbaasRequest/mbaasRequest.js
function doFHMbaaSRequest(params, cb) {
  //Preventing multiple callbacks.
  // _.defaults(undefined, ...) === undefined, so we still need to OR with an empty object
  params = _.defaults(params || {}, {
    headers: {}
  });

  //Adding pagination parameters if required
  params.url = addPaginationUrlParams(params.url, params);

  // add request id header to request if present
  if (_.isFunction(log.logger.getRequestId)) {
    var reqId = log.logger.getRequestId();
    if (reqId) {
      params.headers[log.logger.requestIdHeader] = reqId;
    }
  }

  log.logger.debug({params: params}, "FH-MBAAS-CLIENT: doFHMbaaSRequest");

  var fileData = params.data;

  //If it is a file upload request, the file data is assigned differently
  if (params.fileRequest && params.fileUploadRequest) {
    params.json = false;
  } else {
    //Normal JSON Request
    params.json = true;
    //Dont set a body if it is a get request
    if (params.method === "GET") {
      params.qs = params.data;
    } else {
      params.body = params.data;
    }
  }

  //The data field is no longer needed
  params = _.omit(params, 'data');

  //If Mbaas Request Expects To Send/Recieve Files, then return the request value
  if (params.fileRequest && params.fileUploadRequest) {
    log.logger.debug("FH-MBAAS-CLIENT: doFHMbaaSRequest File Upload Request");
    var formData = {};
    formData[fileData.name] = {
      value: fileData.stream,
      options: {
        filename: fileData.name,
        contentType: fileData.type
      }
    };

    return request({
      method: params.method,
      url: params.url,
      auth: params.auth,
      headers: params.headers,
      formData: formData
    }, responseHandler(params, cb));
  } else if (params.fileRequest) {
    log.logger.debug("FH-MBAAS-CLIENT: doFHMbaaSRequest File Download Request");
    //File Download Request. Return the readable request stream.
    return cb(undefined, request(params));
  } else {
    //Normal call.
    log.logger.debug("FH-MBAAS-CLIENT: doFHMbaaSRequest Normal Request");
    request(params, responseHandler(params, cb));
  }
}
function doFHMbaaSRequest(params, cb) {
  //Preventing multiple callbacks.
  // _.defaults(undefined, ...) === undefined, so we still need to OR with an empty object
  params = _.defaults(params || {}, {
    headers: {}
  });

  //Adding pagination parameters if required
  params.url = addPaginationUrlParams(params.url, params);

  // add request id header to request if present
  if (_.isFunction(log.logger.getRequestId)) {
    var reqId = log.logger.getRequestId();
    if (reqId) {
      params.headers[log.logger.requestIdHeader] = reqId;
    }
  }

  log.logger.debug({params: params}, "FH-MBAAS-CLIENT: doFHMbaaSRequest");

  var fileData = params.data;

  //If it is a file upload request, the file data is assigned differently
  if (params.fileRequest && params.fileUploadRequest) {
    params.json = false;
  } else {
    //Normal JSON Request
    params.json = true;
    //Dont set a body if it is a get request
    if (params.method === "GET") {
      params.qs = params.data;
    } else {
      params.body = params.data;
    }
  }

  //The data field is no longer needed
  params = _.omit(params, 'data');

  //If Mbaas Request Expects To Send/Recieve Files, then return the request value
  if (params.fileRequest && params.fileUploadRequest) {
    log.logger.debug("FH-MBAAS-CLIENT: doFHMbaaSRequest File Upload Request");
    var formData = {};
    formData[fileData.name] = {
      value: fileData.stream,
      options: {
        filename: fileData.name,
        contentType: fileData.type
      }
    };

    return request({
      method: params.method,
      url: params.url,
      auth: params.auth,
      headers: params.headers,
      formData: formData
    }, responseHandler(params, cb));
  } else if (params.fileRequest) {
    log.logger.debug("FH-MBAAS-CLIENT: doFHMbaaSRequest File Download Request");
    //File Download Request. Return the readable request stream.
    return cb(undefined, request(params));
  } else {
    //Normal call.
    log.logger.debug("FH-MBAAS-CLIENT: doFHMbaaSRequest Normal Request");
    request(params, responseHandler(params, cb));
  }
}
function doFHMbaaSRequest ( params , cb ) { //Preventing multiple callbacks. // _.defaults(undefined, ...) === undefined, so we still need to OR with an empty object params = _ . defaults ( params || { } , { headers : { } } ) ; //Adding pagination parameters if required params . url = addPaginationUrlParams ( params . url , params ) ; // add request id header to request if present if ( _ . isFunction ( log . logger . getRequestId ) ) { var reqId = log . logger . getRequestId ( ) ; if ( reqId ) { params . headers [ log . logger . requestIdHeader ] = reqId ; } } log . logger . debug ( { params : params } , "FH-MBAAS-CLIENT: doFHMbaaSRequest" ) ; var fileData = params . data ; //If it is a file upload request, the file data is assigned differently if ( params . fileRequest && params . fileUploadRequest ) { params . json = false ; } else { //Normal JSON Request params . json = true ; //Dont set a body if it is a get request if ( params . method === "GET" ) { params . qs = params . data ; } else { params . body = params . data ; } } //The data field is no longer needed params = _ . omit ( params , 'data' ) ; //If Mbaas Request Expects To Send/Recieve Files, then return the request value if ( params . fileRequest && params . fileUploadRequest ) { log . logger . debug ( "FH-MBAAS-CLIENT: doFHMbaaSRequest File Upload Request" ) ; var formData = { } ; formData [ fileData . name ] = { value : fileData . stream , options : { filename : fileData . name , contentType : fileData . type } } ; return request ( { method : params . method , url : params . url , auth : params . auth , headers : params . headers , formData : formData } , responseHandler ( params , cb ) ) ; } else if ( params . fileRequest ) { log . logger . debug ( "FH-MBAAS-CLIENT: doFHMbaaSRequest File Download Request" ) ; //File Download Request. Return the readable request stream. return cb ( undefined , request ( params ) ) ; } else { //Normal call. log . logger . debug ( "FH-MBAAS-CLIENT: doFHMbaaSRequest Normal Request" ) ; request ( params , responseHandler ( params , cb ) ) ; } }
Perform A Request To An MbaaS
@private
Perform A Request To An MbaaS