@opengis/fastify-table 1.0.56 → 1.0.58

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,5 +1,13 @@
1
1
  # fastify-table
2
2
 
3
+ ## 1.0.58 - 08.07.2024
4
+
5
+ - code optimization
6
+
7
+ ## 1.0.57 - 04.07.2024
8
+
9
+ - fix crud update boolean column
10
+
3
11
  ## 1.0.56 - 04.07.2024
4
12
 
5
13
  - code optimization
@@ -15,7 +15,7 @@ export default async function dataInsert({ table, data, pg: pg1 }) {
15
15
 
16
16
  ( ${filterData?.map((key) => `"${key[0]}"`).join(',')})
17
17
 
18
- values (${filterData?.map((key, i) => `$${i + 1}`).join(',')})
18
+ values (${filterData?.map((key, i) => key[0] === 'geom' ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)` : `$${i + 1}`).join(',')})
19
19
 
20
20
  returning *`;
21
21
 
@@ -12,11 +12,13 @@ export default async function dataUpdate({
12
12
 
13
13
  const names = columns?.map((el) => el.name);
14
14
  const filterData = Object.keys(data)
15
- .filter((el) => data[el] && names?.includes(el));
15
+ .filter((el) => {
16
+ return typeof data[el] === 'boolean' ? true : data[el] && names?.includes(el);
17
+ });
16
18
 
17
19
  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
20
 
19
- const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => `"${key}"=$${i + 2}`).join(',')}
21
+ 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
22
  WHERE ${pk} = $1 returning *`;
21
23
  // console.log(updateDataset);
22
24
  const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
package/crud/index.js CHANGED
@@ -4,16 +4,10 @@ import isFileExists from './funcs/isFileExists.js';
4
4
  import dataUpdate from './funcs/dataUpdate.js';
5
5
  import dataInsert from './funcs/dataInsert.js';
6
6
 
7
- import nextId from './controllers/next.id.js';
8
7
  import update from './controllers/update.js';
9
8
  import insert from './controllers/insert.js';
10
9
  import deleteCrud from './controllers/deleteCrud.js';
11
10
 
12
- import getExtraProperties from './controllers/properties.get.js';
13
- import addExtraProperties from './controllers/properties.add.js';
14
-
15
- // import config from '../config.js';
16
-
17
11
  async function plugin(fastify, config = {}) {
18
12
  const prefix = config.prefix || '/api';
19
13
  // funcs
@@ -25,13 +19,9 @@ async function plugin(fastify, config = {}) {
25
19
  fastify.decorate('isFileExists', isFileExists);
26
20
 
27
21
  // api
28
- fastify.get(`${prefix}/next-id`, {}, nextId);
29
22
  fastify.put(`${prefix}/table/:table/:id`, {}, update);
30
23
  fastify.delete(`${prefix}/table/:table/:id`, {}, deleteCrud);
31
24
  fastify.post(`${prefix}/table/:table`, {}, insert);
32
-
33
- fastify.get(`${prefix}/properties/:id`, {}, getExtraProperties);
34
- fastify.post(`${prefix}/properties/:id`, {}, addExtraProperties);
35
25
  }
36
26
 
37
27
  export default plugin;
package/index.js CHANGED
@@ -13,6 +13,7 @@ import notificationPlugin from './notification/index.js';
13
13
  import widgetPlugin from './widget/index.js';
14
14
  import crudPlugin from './crud/index.js';
15
15
  import policyPlugin from './policy/index.js';
16
+ import utilPlugin from './util/index.js';
16
17
 
17
18
  import pgClients from './pg/pgClients.js';
18
19
 
@@ -81,6 +82,7 @@ async function plugin(fastify, opt) {
81
82
  crudPlugin(fastify, opt);
82
83
  notificationPlugin(fastify, opt);
83
84
  widgetPlugin(fastify, opt);
85
+ utilPlugin(fastify, opt);
84
86
  }
85
87
  export default fp(plugin);
86
88
  // export { rclient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -35,7 +35,7 @@ export default async function data(req) {
35
35
 
36
36
  const keyQuery = query.key && loadTable.key && !params.id ? `${loadTable.key}=$1` : null;
37
37
 
38
- const limit = Math.min(maxLimit, +(query.limit || 10));
38
+ const limit = Math.min(maxLimit, +(query.limit || 20));
39
39
 
40
40
  const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
41
41
  // id, query, filter
@@ -1,4 +1,4 @@
1
- import dataInsert from "../funcs/dataInsert.js";
1
+ import dataInsert from "../../crud/funcs/dataInsert.js";
2
2
 
3
3
  const table = 'crm.properties';
4
4
 
package/util/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import getExtraProperties from './controllers/properties.get.js';
2
+ import addExtraProperties from './controllers/properties.add.js';
3
+ import nextId from './controllers/next.id.js';
4
+
5
+ async function plugin(fastify, config = {}) {
6
+ const prefix = config.prefix || '/api';
7
+
8
+ fastify.get(`${prefix}/next-id`, {}, nextId);
9
+ fastify.get(`${prefix}/properties/:id`, {}, getExtraProperties);
10
+ fastify.post(`${prefix}/properties/:id`, {}, addExtraProperties);
11
+ }
12
+
13
+ export default plugin;
File without changes
File without changes