@opengis/fastify-table 1.3.34 → 1.3.36

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.3.34",
3
+ "version": "1.3.36",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -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,11 +11,14 @@ 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
- const filterQueryArray = decodeURIComponent(filterStr?.replace?.(/%/g, '%25')?.replace?.(/%/g, '\\%')?.replace?.(/(^,)|(,$)/g, ''))?.replace?.(/'/g, "''")?.split?.(/[;|]/) || [];
18
+ const filterQueryArray = filterStr
19
+ ? decodeURIComponent(filterStr?.replace?.(/%/g, '%25')?.replace?.(/%/g, '\\%')?.replace?.(/(^,)|(,$)/g, ''))?.replace?.(/'/g, "''")?.split?.(/[;|]/)
20
+ : filterList?.filter?.(el => el.default && (el.options || el.sql))?.map?.((el) => `${el.name}=${el.default}`) // default filter value form checkboxes, autocomplete or sql-defined only
21
+ || [];
19
22
 
20
23
  const resultList = [];
21
24
 
@@ -64,7 +64,7 @@ export default async function tableAPI(req) {
64
64
 
65
65
  if (query?.sql === '1') return q;
66
66
 
67
- const data = await pg.query(q, [id]).then(el => el.rows[0]);
67
+ const data = await pg.query(q.replace(/{{uid}}/, user?.uid), [id]).then(el => el.rows[0]);
68
68
  if (!data) return { message: 'not found', status: 404 };
69
69
 
70
70
  Object.keys(schema).filter(key => schema[key]?.type === 'DataTable').forEach(key => {
@@ -104,7 +104,15 @@ export default async function dataAPI(req, reply, called) {
104
104
  });
105
105
  }
106
106
 
107
- const checkFilter = [query.filter, query.search, query.state, query.custom].filter((el) => el).length;
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,