@opengis/fastify-table 1.0.85 → 1.0.87

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,10 @@
1
1
  # fastify-table
2
2
 
3
- ## 1.0.85 - 23.08.2024
3
+ ## 1.0.87 - 26.08.2024
4
+
5
+ - change of null handling method of update crud API
6
+
7
+ ## 1.0.86 - 23.08.2024
4
8
 
5
9
  - data API meta cls support
6
10
 
@@ -1,24 +1,24 @@
1
- import getPG from '../../pg/funcs/getPG.js';
2
-
3
- import getMeta from '../../pg/funcs/getMeta.js';
4
-
5
- export default async function dataUpdate({
6
- table, id, data, pg: pg1,
7
- }) {
8
- if (!data || !table || !id) return null;
9
-
10
- const pg = pg1 || getPG({ name: 'client' });
11
- const { columns, pk } = await getMeta(table);
12
-
13
- const names = columns?.map((el) => el.name);
14
- const filterData = Object.keys(data)
15
- .filter((el) => (typeof data[el] === 'boolean' ? true : data[el] && names?.includes(el)));
16
-
17
- const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
18
-
19
- const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`)).join(',')}
20
- WHERE ${pk} = $1 returning *`;
21
- // console.log(updateDataset);
22
- const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
23
- return res;
24
- }
1
+ import getPG from '../../pg/funcs/getPG.js';
2
+
3
+ import getMeta from '../../pg/funcs/getMeta.js';
4
+
5
+ export default async function dataUpdate({
6
+ table, id, data, pg: pg1,
7
+ }) {
8
+ if (!data || !table || !id) return null;
9
+
10
+ const pg = pg1 || getPG({ name: 'client' });
11
+ const { columns, pk } = await getMeta(table);
12
+
13
+ const names = columns?.map((el) => el.name);
14
+ const filterData = Object.keys(data)
15
+ .filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el)));
16
+
17
+ const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
18
+
19
+ const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`)).join(',')}
20
+ WHERE ${pk} = $1 returning *`;
21
+ // console.log(updateQuery, filterValue);
22
+ const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
23
+ return res;
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.0.85",
3
+ "version": "1.0.87",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
package/table/index.js CHANGED
@@ -11,7 +11,7 @@ import getTemplate from './controllers/utils/getTemplate.js';
11
11
  import getSelect from './controllers/utils/getSelect.js';
12
12
 
13
13
  const tableSchema = {
14
- querystring: {
14
+ querystring1: {
15
15
  page: { type: 'string', pattern: '^(\\d+)$' },
16
16
  order: { type: 'string', pattern: '^(\\d+)$' },
17
17
  filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([\\w\\d_-]+)$' },
@@ -18,7 +18,7 @@ test('api table', async (t) => {
18
18
  await t.test('GET /data (meta bbox / cls)', async () => {
19
19
  const res = await app.inject({
20
20
  method: 'GET',
21
- url: `${config.prefix || '/api'}/data/test.dataset.table?bbox=${bbox}&json=1`,
21
+ url: `${config.prefix || '/api'}/data/test.dataset.table?bbox=${bbox}`,
22
22
  });
23
23
  const json = res.json();
24
24
  assert.ok(json?.rows?.length === +count, 'meta bbox - not ok');