@opengis/fastify-table 1.0.15 → 1.0.17

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.
@@ -1,7 +1,11 @@
1
1
  import dataDelete from '../funcs/dataDelete.js';
2
+ import getTemplate from '../../table/controllers/utils/getTemplate.js';
2
3
 
3
4
  export default async function deleteCrud(req) {
4
- const { table, id } = req.params || {};
5
+ const loadTemplate = await getTemplate('table', req.params.table);
6
+ const { table } = loadTemplate || req.params || {};
7
+ const { id } = req.params || {};
8
+
5
9
  if (!table) return { status: 404, message: 'table is required' };
6
10
 
7
11
  const data = await dataDelete({ table, id });
@@ -4,7 +4,8 @@ import checkXSS from './utils/checkXSS.js';
4
4
  import getTemplate from '../../table/controllers/utils/getTemplate.js';
5
5
 
6
6
  export default async function insert(req) {
7
- const { table } = req.params || {};
7
+ const loadTemplate = await getTemplate('table', req.params.table);
8
+ const { table } = loadTemplate || req.params || {};
8
9
  if (!table) return { status: 404, message: 'table is required' };
9
10
 
10
11
  const { funcs, session, params } = req;
@@ -24,5 +25,5 @@ export default async function insert(req) {
24
25
  }
25
26
 
26
27
  const res = await dataInsert({ table: add || table, data: req.body });
27
- return res;
28
+ return { rows: res.rows };
28
29
  }
@@ -4,7 +4,9 @@ import checkXSS from './utils/checkXSS.js';
4
4
  import getTemplate from '../../table/controllers/utils/getTemplate.js';
5
5
 
6
6
  export default async function update(req) {
7
- const { table, id } = req.params || {};
7
+ const loadTemplate = await getTemplate('table', req.params.table);
8
+ const { table } = loadTemplate || req.params || {};
9
+ const { id } = req.params || {};
8
10
  if (!req.params?.table) return { message: 'table is required', status: 404 };
9
11
  if (!id) return { message: 'id is required', status: 404 };
10
12
 
@@ -15,7 +15,7 @@ function checkXSS({ body, schema = {} }) {
15
15
 
16
16
  // escape arrows on non-RTE
17
17
  Object.keys(body)
18
- .filter((key) => ['<', '>'].find((el) => body[key].includes(el))
18
+ .filter((key) => ['<', '>'].find((el) => body[key]?.includes?.(el))
19
19
  && !['Summernote', 'Tiny', 'Ace'].includes(schema[key]?.type))
20
20
  ?.forEach((key) => {
21
21
  Object.assign(body, { [key]: body[key].replace(/</g, '&lt;').replace(/>/g, '&gt;') });
@@ -18,7 +18,7 @@ export default async function dataInsert({ table, data }) {
18
18
  values (${filterData?.map((key, i) => `$${i + 1}`).join(',')})
19
19
 
20
20
  returning *`;
21
- await pg.query('DROP TRIGGER if exists dataset_before_update_insert ON gis.dataset');
22
- const res = await pg.one(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' ? JSON.stringify(el[1]) : el[1]))]) || {};
21
+
22
+ const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' ? JSON.stringify(el[1]) : el[1]))]) || {};
23
23
  return res;
24
24
  }
package/crud/index.js CHANGED
@@ -21,9 +21,9 @@ async function plugin(fastify, config = {}) {
21
21
  fastify.decorate('isFileExists', isFileExists);
22
22
 
23
23
  // api
24
- fastify.put(`${prefix}/crud/:table/:id`, {}, update);
25
- fastify.delete(`${prefix}/crud/:table/:id`, {}, deleteCrud);
26
- fastify.post(`${prefix}/crud/:table`, {}, insert);
24
+ fastify.put(`${prefix}/table/:table/:id`, {}, update);
25
+ fastify.delete(`${prefix}/table/:table/:id`, {}, deleteCrud);
26
+ fastify.post(`${prefix}/table/:table`, {}, insert);
27
27
  }
28
28
 
29
29
  export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",