@opengis/fastify-table 1.3.35 → 1.3.37
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
|
@@ -4,7 +4,7 @@ import getRangeQuery from "./getRangeQuery.js";
|
|
|
4
4
|
export default function formatValue({
|
|
5
5
|
pg, table, filter = {}, name, value, dataTypeID, uid = 1, optimize,
|
|
6
6
|
}) {
|
|
7
|
-
const { extra, sql, select, strict, options } = filter;
|
|
7
|
+
const { extra, sql, select, strict, options, default: defaultValue } = filter;
|
|
8
8
|
const pk = pg?.pk && table ? pg.pk[table] : undefined;
|
|
9
9
|
|
|
10
10
|
const filterType = filter.type?.toLowerCase() || 'text';
|
|
@@ -11,16 +11,21 @@ import formatValue from './formatValue.js';
|
|
|
11
11
|
function getQuery({
|
|
12
12
|
pg, filter: filterStr, table, tableSQL, fields, filterList, uid,
|
|
13
13
|
}) {
|
|
14
|
-
if (!filterStr) return null; // filter list API
|
|
14
|
+
// if (!filterStr) return null; // filter list API
|
|
15
15
|
|
|
16
16
|
const mainOperators = ['=', '~', '>', '<'];
|
|
17
17
|
|
|
18
18
|
const filterQueryArray = decodeURIComponent(filterStr?.replace?.(/%/g, '%25')?.replace?.(/%/g, '\\%')?.replace?.(/(^,)|(,$)/g, ''))?.replace?.(/'/g, "''")?.split?.(/[;|]/) || [];
|
|
19
|
+
// default filter value form checkboxes, autocomplete or sql-defined only
|
|
20
|
+
const filterDefaultQueryArray = filterList?.filter?.(el => el.name && !filterStr?.includes?.(`${el.name}=`) && el.default && (el.options || el.sql))?.map?.((el) => `${el.name}=${el.default}`) || [];
|
|
21
|
+
|
|
22
|
+
// concat default + request filters
|
|
23
|
+
const arr = filterQueryArray.concat(filterDefaultQueryArray).filter(el => el);
|
|
19
24
|
|
|
20
25
|
const resultList = [];
|
|
21
26
|
|
|
22
|
-
for (let i = 0; i <
|
|
23
|
-
const item =
|
|
27
|
+
for (let i = 0; i < arr.length; i += 1) {
|
|
28
|
+
const item = arr[i];
|
|
24
29
|
const splitby = mainOperators?.find((el) => item.indexOf(el) !== -1) || '=';
|
|
25
30
|
const [name] = item.split(splitby);
|
|
26
31
|
|
|
@@ -34,7 +39,7 @@ function getQuery({
|
|
|
34
39
|
const { strict, extra } = filter;
|
|
35
40
|
|
|
36
41
|
// find all value
|
|
37
|
-
const value =
|
|
42
|
+
const value = arr.filter((el) => el.split(splitby)?.[0] === name).map((el) => el.substring(name.length + 1)).join(',');
|
|
38
43
|
|
|
39
44
|
const optimize = fields?.find((el) => el.name === name) ? null : tableSQL.find((el) => el.name === name);
|
|
40
45
|
|
|
@@ -104,7 +104,15 @@ export default async function dataAPI(req, reply, called) {
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
const
|
|
107
|
+
const isdefault = (loadTable?.filter_list || [])
|
|
108
|
+
.concat(loadTable?.filterInline || [])
|
|
109
|
+
.concat(loadTable?.filterCustom || [])
|
|
110
|
+
.concat(loadTable?.filterState || [])
|
|
111
|
+
.concat(loadTable?.filterList || [])
|
|
112
|
+
.concat(loadTable?.filters || [])
|
|
113
|
+
.find(el => el.default);
|
|
114
|
+
|
|
115
|
+
const checkFilter = [query.filter, query.search, query.state, query.custom, isdefault].filter((el) => el).length;
|
|
108
116
|
|
|
109
117
|
const fData = checkFilter ? await getFilterSQL({
|
|
110
118
|
pg,
|