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.
|
@@ -451,7 +451,7 @@ class MysqlAdapter {
|
|
|
451
451
|
let total = null;
|
|
452
452
|
;
|
|
453
453
|
if (request.calculateCount) {
|
|
454
|
-
const cres = await conn.query(
|
|
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
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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;
|