@opengis/fastify-table 1.3.13 → 1.3.15
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/package.json
CHANGED
|
@@ -38,6 +38,9 @@ export default async function dataInsert({
|
|
|
38
38
|
|
|
39
39
|
const filterData = Object.keys(data)
|
|
40
40
|
.filter((el) => !['cdate', 'editor_date'].includes(el) && (typeof data[el] === 'boolean' ? true : data[el]) && names.includes(el)).map((el) => [el, data[el]]);
|
|
41
|
+
if (!filterData?.length) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
41
44
|
|
|
42
45
|
const insertQuery = `insert into ${table}
|
|
43
46
|
|
|
@@ -27,43 +27,21 @@ export default async function extraData({
|
|
|
27
27
|
|| defaultTable;
|
|
28
28
|
|
|
29
29
|
const { pk: mainPK, columns: mainColumns = [] } = await getMeta({ pg, table });
|
|
30
|
-
const { pk, columns: extraColumns = [] } = await getMeta({ pg, table: extraDataTable });
|
|
31
30
|
|
|
32
31
|
if (!mainPK) {
|
|
33
32
|
return { error: `table pk not found: ${table}`, status: 404 };
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
if (!pk) {
|
|
35
|
+
if (!pg.pk?.[extraDataTable]) {
|
|
37
36
|
return { error: `extra table pk not found: ${extraDataTable}`, status: 404 };
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
? 'column'
|
|
42
|
-
: 'property';
|
|
39
|
+
Object.assign(data || {}, { object_id: id });
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
Object.assign(data || {}, { object_id: id });
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const deleteRes = mode === 'property'
|
|
49
|
-
? await pg.query(`delete from ${extraDataTable} where object_id=$1 and property_key = any($2::text[]) returning *`, [id, Object.keys(loadTemplate?.schema || {})])
|
|
50
|
-
: await pg.query(`delete from ${extraDataTable} where ${mainPK}=$1 returning *`, [id]);
|
|
41
|
+
const deleteRes = await pg.query(`delete from ${extraDataTable} where object_id=$1 and property_key = any($2::text[]) returning *`, [id, Object.keys(loadTemplate?.schema || {})]);
|
|
51
42
|
|
|
52
43
|
if (!data) {
|
|
53
|
-
|
|
54
|
-
? deleteRes?.rows?.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: format(curr.property_key, curr.value_text, loadTemplate?.schema) }), {})
|
|
55
|
-
: deleteRes?.rows?.[0];
|
|
56
|
-
return res1;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (mode === 'column') {
|
|
60
|
-
const filteredData = Object.keys(data)
|
|
61
|
-
.filter(key => Object.keys(loadTemplate?.schema || {}).includes(key))
|
|
62
|
-
.reduce((acc, curr) => Object.assign(acc, { [curr]: data[curr] }), {});
|
|
63
|
-
Object.assign(filteredData, { [mainPK]: id });
|
|
64
|
-
const res = await dataInsert({ pg, table: extraDataTable, data: filteredData, uid }).then(el => el.rows?.[0] || {});
|
|
65
|
-
Object.assign(res, { id: res?.[pg.pk?.[table || '']] });
|
|
66
|
-
return res;
|
|
44
|
+
return deleteRes?.rows?.reduce?.((acc, curr) => Object.assign(acc, { [curr.property_key]: format(curr.property_key, curr.value_text, loadTemplate?.schema) }), {});
|
|
67
45
|
}
|
|
68
46
|
|
|
69
47
|
const rows = Object.keys(data || {})
|
|
@@ -11,7 +11,7 @@ function close() {
|
|
|
11
11
|
|
|
12
12
|
async function getHeadersPG(req, config) {
|
|
13
13
|
if (!req.headers?.token) return null;
|
|
14
|
-
const validToken = (req.ip === '127.0.0.1' || req.ip.startsWith('192.168.') || config.debug) && req.headers?.
|
|
14
|
+
const validToken = (req.ip === '193.239.152.181' || req.ip === '127.0.0.1' || req.ip.startsWith('192.168.') || config.debug) && req.headers?.token && config.auth?.tokens?.includes?.(req.headers.token);
|
|
15
15
|
|
|
16
16
|
if (validToken && req.headers?.db) {
|
|
17
17
|
const pg = pgClients[req.headers.db]
|
|
@@ -67,7 +67,6 @@ export default function checkPolicy(req, reply) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
const validToken = (req.ip === '193.239.152.181' || req.ip === '127.0.0.1' || req.ip?.startsWith?.('192.168.') || config.debug)
|
|
70
|
-
&& req.headers?.uid
|
|
71
70
|
&& req.headers?.token
|
|
72
71
|
&& config.auth?.tokens?.includes?.(headers.token);
|
|
73
72
|
|
|
@@ -2,6 +2,8 @@ import {
|
|
|
2
2
|
config, getAccess, getTemplate, getMeta, setToken, applyHook, getToken, pgClients,
|
|
3
3
|
} from '../../../../utils.js';
|
|
4
4
|
|
|
5
|
+
import extraDataGet from '../../../plugins/extra/extraDataGet.js';
|
|
6
|
+
|
|
5
7
|
export default async function tableAPI(req) {
|
|
6
8
|
const {
|
|
7
9
|
pg = pgClients.client, params, user = {}, query = {},
|
|
@@ -85,8 +87,12 @@ export default async function tableAPI(req) {
|
|
|
85
87
|
array: 1,
|
|
86
88
|
})[0];
|
|
87
89
|
}
|
|
90
|
+
|
|
91
|
+
await extraDataGet({ rows: [data], table: tableName, form: hookData?.form || tokenData?.form || loadTable.form }, pg);
|
|
92
|
+
|
|
88
93
|
const res = await applyHook('afterTable', {
|
|
89
94
|
pg, table: tableName, payload: [data], user,
|
|
90
95
|
});
|
|
96
|
+
|
|
91
97
|
return res || data || {};
|
|
92
98
|
}
|