@opengis/fastify-table 1.0.14 → 1.0.16
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
|
|
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
|
|
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
|
|
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]
|
|
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, '<').replace(/>/g, '>') });
|
package/crud/funcs/dataInsert.js
CHANGED
|
@@ -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
|
-
|
|
22
|
-
const res = await pg.
|
|
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
|
}
|