rez_core 4.0.61 → 4.0.62
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.
package/package.json
CHANGED
|
@@ -28,6 +28,7 @@ export class FilterService {
|
|
|
28
28
|
private readonly skipAppCodeFilterEntities = ['ORGP'];
|
|
29
29
|
private readonly skipOrgFilterEntities = ['ORGP'];
|
|
30
30
|
|
|
31
|
+
|
|
31
32
|
private async gettab_value_counts(
|
|
32
33
|
tableName: string,
|
|
33
34
|
column: string | undefined,
|
|
@@ -35,80 +36,54 @@ export class FilterService {
|
|
|
35
36
|
) {
|
|
36
37
|
if (!column) return [];
|
|
37
38
|
|
|
38
|
-
// ✅ Validate tableName and column to prevent SQL injection
|
|
39
|
-
if (!/^[a-zA-Z0-9_]+$/.test(tableName) || !/^[a-zA-Z0-9_]+$/.test(column)) {
|
|
40
|
-
throw new Error('Invalid table or column name');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
39
|
let whereSQL = '';
|
|
44
40
|
const values: any[] = [];
|
|
45
41
|
|
|
46
42
|
if (whereClauses.length > 0) {
|
|
47
43
|
const clauseParts = whereClauses.map((clause) => {
|
|
48
|
-
|
|
49
|
-
let parsedQuery = clause.query.replace(/\be\./g, '');
|
|
44
|
+
let parsedQuery = clause.query.replace(/\be\./g, ''); // remove e.
|
|
50
45
|
|
|
51
46
|
Object.entries(clause.params).forEach(([key, val]) => {
|
|
52
47
|
if (Array.isArray(val)) {
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
`IN (${val.map(() => '?').join(', ')})`,
|
|
58
|
-
);
|
|
59
|
-
} else {
|
|
60
|
-
parsedQuery = parsedQuery.replace(
|
|
61
|
-
new RegExp(`:\\b${key}\\b`, 'g'),
|
|
62
|
-
val.map(() => '?').join(', '),
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
values.push(...val);
|
|
48
|
+
// if it's an array → expand placeholders (?, ?, ?)
|
|
49
|
+
const placeholders = val.map(() => '?').join(', ');
|
|
50
|
+
parsedQuery = parsedQuery.replace(new RegExp(`:${key}`, 'g'), `(${placeholders})`);
|
|
51
|
+
values.push(...val); // flatten values
|
|
66
52
|
} else {
|
|
67
|
-
parsedQuery = parsedQuery.replace(
|
|
68
|
-
new RegExp(`:\\b${key}\\b`, 'g'),
|
|
69
|
-
'?',
|
|
70
|
-
);
|
|
53
|
+
parsedQuery = parsedQuery.replace(new RegExp(`:${key}`, 'g'), '?');
|
|
71
54
|
values.push(val);
|
|
72
55
|
}
|
|
73
56
|
});
|
|
74
57
|
|
|
75
|
-
|
|
76
|
-
return `(${parsedQuery})`;
|
|
58
|
+
return parsedQuery;
|
|
77
59
|
});
|
|
78
60
|
|
|
79
61
|
whereSQL = `WHERE ${clauseParts.join(' AND ')}`;
|
|
80
62
|
}
|
|
81
63
|
|
|
82
|
-
// ✅ Wrap identifiers in backticks for MySQL or double quotes for Postgres
|
|
83
64
|
const rawSQL = `
|
|
84
|
-
SELECT
|
|
85
|
-
${column} AS tab_value,
|
|
86
|
-
COUNT(*) AS tab_value_count
|
|
65
|
+
SELECT ${column} AS tab_value, COUNT(*) AS tab_value_count
|
|
87
66
|
FROM ${tableName}
|
|
88
67
|
${whereSQL}
|
|
89
68
|
GROUP BY ${column}
|
|
90
|
-
ORDER BY tab_value_count DESC
|
|
91
69
|
`;
|
|
92
70
|
|
|
93
71
|
const rows = await this.dataSource.query(rawSQL, values);
|
|
94
72
|
|
|
95
|
-
// ✅ Handle total count safely
|
|
96
73
|
const total = rows.reduce(
|
|
97
|
-
(sum, r) => sum +
|
|
74
|
+
(sum, r) => sum + parseInt(r.tab_value_count, 10),
|
|
98
75
|
0,
|
|
99
76
|
);
|
|
100
77
|
|
|
101
|
-
// ✅ Ensure consistent response
|
|
102
78
|
return [
|
|
103
79
|
{ tab_value: 'All', tab_value_count: total },
|
|
104
80
|
...rows.map((r) => ({
|
|
105
81
|
tab_value: r.tab_value ?? 'UNKNOWN',
|
|
106
|
-
tab_value_count:
|
|
82
|
+
tab_value_count: parseInt(r.tab_value_count, 10),
|
|
107
83
|
})),
|
|
108
84
|
];
|
|
109
85
|
}
|
|
110
86
|
|
|
111
|
-
|
|
112
87
|
|
|
113
88
|
async applyFilterWrapper(dto: FilterRequestDto) {
|
|
114
89
|
const {
|