@opengis/fastify-table 1.1.28 → 1.1.29

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/Changelog.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # fastify-table
2
2
 
3
- ## 1.1.28 - 09.10.2024
3
+ ## 1.1.29 - 09.10.2024
4
4
 
5
5
  - add after crud hook
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.28",
3
+ "version": "1.1.29",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -1,4 +1,5 @@
1
1
  create schema if not exists admin;
2
+ create schema if not exists setting;
2
3
 
3
4
  -- DROP TABLE admin.properties;
4
5
  CREATE TABLE IF NOT EXISTS admin.properties();
@@ -19,7 +19,7 @@ function formatDateISOString(date) {
19
19
  }
20
20
 
21
21
  function formatValue({
22
- clsList, filterType, filter, name, value, operator = '=', fieldType = 'text', uid = 1, optimize,
22
+ filterType, filter, name, value, operator = '=', fieldType = 'text', uid = 1, optimize,
23
23
  }) {
24
24
  if (!name || !value) return {};
25
25
 
@@ -105,7 +105,7 @@ function formatValue({
105
105
  return { op: operator, query };
106
106
  }
107
107
 
108
- if (operator === '=' && filterType !== 'text') {
108
+ if (operator === '=' && filterType !== 'text' && !filter?.data) {
109
109
  const query = {
110
110
  null: `${name} is null`,
111
111
  notnull: `${name} is not null`,
@@ -114,9 +114,12 @@ function formatValue({
114
114
  }
115
115
 
116
116
  if (['~', '='].includes(operator)) {
117
- const query = clsList[filter?.data]
118
- ? `${filter?.name} in ( ( with q(id,name) as (${clsList?.[filter?.data]}) select id from q where name ilike '%${value}%') )` // filter with cls
119
- : `${name}::text ilike '%${value}%'`; // simple filter
117
+ const operator1 = (filterType === 'text' && (filter?.id || filter?.name) && operator === '=' ? '~' : operator);
118
+ const match = operator1 === '=' ? `='${value}'` : `ilike '%${value}%'`;
119
+ const query = filter?.data && filter?.sql
120
+ ? `${filter?.name || filter?.id} in ( ( with q(id,name) as (${filter?.sql}) select id from q where name::text ${match}) )` // filter with cls
121
+ : `${name}::text ${match}`; // simple filter
122
+ // console.log(query);
120
123
  return { op: 'ilike', query };
121
124
  }
122
125
 
@@ -5,8 +5,8 @@ export default function obj2db(data, nonexistCol) {
5
5
  || !Object.keys(data || {}).length
6
6
  ) return { error: 'invalid data type' };
7
7
 
8
- const existColumns = Object.keys(data)?.filter((key) => !nonexistCol.includes(key));
9
- const columns = existColumns?.filter((col) => data[col] || data?.[col] === 0);
8
+ const columns = Object.keys(data)?.filter((key) => !nonexistCol.includes(key));
9
+ // const columns = existColumns?.filter((col) => data[col] || data?.[col] === 0);
10
10
  const args = columns?.map((col) => data[col]);
11
11
 
12
12
  return { columns, args, error: !columns?.length ? 'nothing to process' : undefined };