@opengis/fastify-table 2.0.153 → 2.0.154
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logChanges.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/crud/funcs/utils/logChanges.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"logChanges.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/crud/funcs/utils/logChanges.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AA6C5D,wBAA8B,UAAU,CAAC,EACvC,EAAE,EACF,KAAK,EAAE,MAAM,EACb,SAAS,EACT,OAAO,EACP,EAAE,EACF,IAAI,EACJ,GAAO,EACP,IAAI,GACL,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;CACd;;;;;;;;;;;;;;;;;;;;UA4MA"}
|
|
@@ -2,6 +2,8 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import getTemplate from "../../../table/funcs/getTemplate.js";
|
|
3
3
|
import metaFormat from "../../../table/funcs/metaFormat/index.js";
|
|
4
4
|
import getMeta from "../../../pg/funcs/getMeta.js";
|
|
5
|
+
import config from "../../../../../config.js";
|
|
6
|
+
const logLength = +(config.logLength || 200);
|
|
5
7
|
const defaultTitles = {
|
|
6
8
|
editor_date: "Дата оновлення",
|
|
7
9
|
editor_id: "Редактор",
|
|
@@ -26,7 +28,7 @@ const systemColumns = [
|
|
|
26
28
|
"updated_by",
|
|
27
29
|
"created_by",
|
|
28
30
|
];
|
|
29
|
-
function getValue(val, tableName
|
|
31
|
+
function getValue(val, tableName) {
|
|
30
32
|
if (typeof val === "boolean")
|
|
31
33
|
return val;
|
|
32
34
|
if (!val)
|
|
@@ -34,7 +36,9 @@ function getValue(val, tableName, columnTypes) {
|
|
|
34
36
|
if (["crm.files"].includes(tableName)) {
|
|
35
37
|
return typeof val === "object" ? JSON.stringify(val) : val;
|
|
36
38
|
}
|
|
37
|
-
return typeof val === "object"
|
|
39
|
+
return typeof val === "object"
|
|
40
|
+
? null
|
|
41
|
+
: val?.toString?.()?.substring?.(0, logLength);
|
|
38
42
|
}
|
|
39
43
|
// extract titles and cls from form schema
|
|
40
44
|
// alt: extract table template from referer -> form
|
|
@@ -112,7 +116,7 @@ export default async function logChanges({ pg, table: table1, tokenData, referer
|
|
|
112
116
|
[titles[curr] || curr]: columnTypes[curr] === "geometry"
|
|
113
117
|
? {}
|
|
114
118
|
: {
|
|
115
|
-
value: getValue(row[curr], table
|
|
119
|
+
value: getValue(row[curr], table),
|
|
116
120
|
hash: typeof row[curr] === "boolean" || row[curr]
|
|
117
121
|
? createHash("md5")
|
|
118
122
|
.update(JSON.stringify(row[curr]))
|
|
@@ -123,22 +127,20 @@ export default async function logChanges({ pg, table: table1, tokenData, referer
|
|
|
123
127
|
return acc;
|
|
124
128
|
});
|
|
125
129
|
}
|
|
126
|
-
await Promise.all(Object.keys(row)
|
|
130
|
+
await Promise.all(Object.keys(row || {})
|
|
127
131
|
.filter((key) => row[key] && columnTypes[key] === "geometry")
|
|
128
132
|
.map(async (key) => pg
|
|
129
|
-
.query(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
.then((el) => ({ key, geometry: el.rows[0].st_asgeojson })))).then((r) => r.forEach((curr) => {
|
|
133
|
-
const value = curr.geometry.coordinates.join(",");
|
|
133
|
+
.query("select st_astext($1)", [row[key]])
|
|
134
|
+
.then((el) => ({ key, value: el.rows[0].st_astext })))).then((r) => r.forEach((curr) => {
|
|
135
|
+
const { key, value } = curr;
|
|
134
136
|
const hash = createHash("md5")
|
|
135
137
|
.update(JSON.stringify(value))
|
|
136
138
|
.digest("hex");
|
|
137
|
-
if (titles[
|
|
138
|
-
newObj1[titles[
|
|
139
|
+
if (titles[key]) {
|
|
140
|
+
newObj1[titles[key]] = { value, hash };
|
|
139
141
|
}
|
|
140
142
|
else {
|
|
141
|
-
newObj1[
|
|
143
|
+
newObj1[key] = { value, hash };
|
|
142
144
|
}
|
|
143
145
|
}));
|
|
144
146
|
const changesData = Object.keys(newObj1 || {})
|