badmfck-api-server 4.0.64 → 4.0.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -95,7 +95,7 @@ async function Initializer(services) {
95
95
  }
96
96
  exports.Initializer = Initializer;
97
97
  class APIService extends BaseService_1.BaseService {
98
- version = "4.0.64";
98
+ version = "4.0.65";
99
99
  options;
100
100
  monitor = null;
101
101
  started = new Date();
@@ -451,7 +451,7 @@ class MysqlAdapter {
451
451
  let total = null;
452
452
  ;
453
453
  if (request.calculateCount) {
454
- const cres = await conn.query("SELECT FOUND_ROWS() as total");
454
+ const cres = await conn.query(this.prepareCountQuery(query));
455
455
  if (cres && cres[0]) {
456
456
  const res = cres[0];
457
457
  if (Array.isArray(res) && res.length > 0 && "total" in res[0])
@@ -644,14 +644,11 @@ class MysqlAdapter {
644
644
  return value;
645
645
  }
646
646
  prepareCountQuery(query) {
647
- let countQuery = query;
648
- if (countQuery.indexOf("LIMIT") === -1)
649
- countQuery = countQuery.substring(0, countQuery.indexOf("LIMIT"));
650
- if (countQuery.indexOf("ORDER") !== -1)
651
- countQuery = countQuery.substring(0, countQuery.indexOf("ORDER"));
652
- countQuery = countQuery.substring(countQuery.indexOf("FROM"));
653
- countQuery = "SELECT COUNT(1) as `count` " + countQuery;
654
- return countQuery;
647
+ let cleanQuery = query
648
+ .replace(/ORDER\s+BY\s+.*$/is, "")
649
+ .replace(/\bLIMIT\s+\d+(\s+OFFSET\s+\d+)?/is, "")
650
+ .trim();
651
+ return `SELECT COUNT(1) AS \`count\` FROM (${cleanQuery}) AS \`temp_count_table\``;
655
652
  }
656
653
  async commit(trx) {
657
654
  try {
@@ -55,9 +55,10 @@ class MicroserviceClient extends BaseService_1.BaseService {
55
55
  const resp = await Http_1.Http.post(url, { tag: tag.toString("base64"), enc: encrypted.toString("base64") }, { headers });
56
56
  if (!resp.ok)
57
57
  return { ...DefaultErrors_1.default.BAD_REQUEST, details: resp.details, stack: [resp.error] };
58
- if (resp.data && typeof resp.data === "object" && "error" in resp.data)
59
- return resp.data.error;
60
- return resp.data;
58
+ const body = resp.data;
59
+ if (body && typeof body === "object" && "error" in body)
60
+ return body.error;
61
+ return body.data ?? null;
61
62
  }
62
63
  }
63
64
  exports.MicroserviceClient = MicroserviceClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "4.0.64",
3
+ "version": "4.0.65",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",