postFetchRequest method

dynamic postFetchRequest(
  1. String apiBaseURL,
  2. dynamic model,
  3. int pageNo,
  4. bool includeChild, [
  5. dynamic jsonPacket,
])

Implementation

postFetchRequest(
    String apiBaseURL, dynamic model, int pageNo, bool includeChild,
    [dynamic jsonPacket]) async {
  var userID = await Libs.prefGet('UserId') ?? 0;
  var userGuID = await Libs.prefGet('UserGuid') ?? 0;
  print('query:' +
      Models.models[model.runtimeType.toString()]!.whereFetch.toString());
  var where = Models.models[model.runtimeType.toString()]!.whereFetch
      .toString()
      .replaceAll("{SystemUser}", userID.toString());

  //where = where.isEmpty ? ' UserId = $userID' : ' and UserId = $userID';
  var select = Models.models[model.runtimeType.toString()]!.selectFetch
      .toString()
      .replaceAll("{SystemUser}", userID.toString());

  where = await processPrefKey(where);
  select = await processPrefKey(select);
  var order = Models.models[model.runtimeType.toString()]!.orderFetch;

  var modelName = model.runtimeType.toString();
  packet() => {
        "ModelName": "$modelName",
        "Select": "$select",
        "Where": "$where",
        "OrderBy": "",
        "IncludeChild": includeChild
      };
  //packet() => {"ModelName": "$modelName", "Select": "", "Where": "", "OrderBy": "", "IncludeChild": true};

  fetchRequest['ApiPacket'] = {
    "Packet": jsonPacket ?? packet(),
    "PacketList": null
  };
  fetchRequest['TableName'] = modelName;
  fetchRequest['PageNo'] = pageNo;
  fetchRequest['UserGuid'] = userGuID;

  print('Post Request Call: $pageNo');
  fetchRequest['TotalRecord'] = pageNo == 1 ? 1 : 0;
  print('Request Body $pageNo : ' + json.encode(fetchRequest));
  var apiResponse = await http
      .post(Uri.parse(apiBaseURL), body: json.encode(fetchRequest), headers: {
    HttpHeaders.contentTypeHeader: "application/json",
  });
  await dbHelper.insertDataHistory(
      modelName, json.encode(fetchRequest), apiResponse.body);
  return apiResponse;
}