@opengis/fastify-table 2.0.153 → 2.0.155
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/dist/server/plugins/crud/funcs/utils/logChanges.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/utils/logChanges.js +14 -12
- package/dist/server/routes/crud/controllers/insert.d.ts.map +1 -1
- package/dist/server/routes/crud/controllers/insert.js +12 -2
- package/dist/server/routes/widget/controllers/widget.get.d.ts.map +1 -1
- package/dist/server/routes/widget/controllers/widget.get.js +3 -1
- package/package.json +1 -1
|
@@ -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 || {})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/insert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAe5C,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"insert.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/insert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAe5C,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBAyMjE"}
|
|
@@ -130,6 +130,17 @@ export default async function insert(req, reply) {
|
|
|
130
130
|
if (!res) {
|
|
131
131
|
return reply.status(400).send({ error: "nothing added", code: 400 });
|
|
132
132
|
}
|
|
133
|
+
const pk = pg.pk?.[loadTemplate?.table || table];
|
|
134
|
+
const id = res[pk];
|
|
135
|
+
if (Array.isArray(body.files)) {
|
|
136
|
+
await Promise.all(body.files
|
|
137
|
+
.filter((el) => el.file_id && el.file_path)
|
|
138
|
+
.map(async (el) => pg.query("update crm.files set entity_id=$1 where entity_id = 'uploads' and file_id=$2 and file_path=$3", [id, el.file_id, el.file_path])));
|
|
139
|
+
}
|
|
140
|
+
// remove stale files
|
|
141
|
+
// await pg.query(
|
|
142
|
+
// "delete from crm.files where entity_id = 'uploads' and cdate < now() - interval '1 day'"
|
|
143
|
+
// );
|
|
133
144
|
// admin.custom_column
|
|
134
145
|
await applyHook("afterInsert", {
|
|
135
146
|
pg,
|
|
@@ -139,8 +150,7 @@ export default async function insert(req, reply) {
|
|
|
139
150
|
payload: res,
|
|
140
151
|
user,
|
|
141
152
|
});
|
|
142
|
-
const pk = pg.pk?.[loadTemplate?.table || table];
|
|
143
153
|
return reply
|
|
144
154
|
.status(200)
|
|
145
|
-
.send({ id
|
|
155
|
+
.send({ id, rows: res.rows, extra: res.extra, ...(res || {}) });
|
|
146
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.get.d.ts","sourceRoot":"","sources":["../../../../../server/routes/widget/controllers/widget.get.ts"],"names":[],"mappings":"AAyBA;;;GAGG;AAEH,wBAA8B,SAAS,CACrC,EAAE,EAAqB,EAAE,IAAS,EAAE,MAAW,EAAE,KAAU,EAAE,EAAE,GAAG,EAClE,KAAK,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"widget.get.d.ts","sourceRoot":"","sources":["../../../../../server/routes/widget/controllers/widget.get.ts"],"names":[],"mappings":"AAyBA;;;GAGG;AAEH,wBAA8B,SAAS,CACrC,EAAE,EAAqB,EAAE,IAAS,EAAE,MAAW,EAAE,KAAU,EAAE,EAAE,GAAG,EAClE,KAAK,EAAE,GAAG,gBAyLX"}
|
|
@@ -124,7 +124,9 @@ export default async function widgetGet({ pg = pgClients.client, user = {}, para
|
|
|
124
124
|
!process.env.VITEST) {
|
|
125
125
|
return reply.status(404).send("log table not found");
|
|
126
126
|
}
|
|
127
|
-
const
|
|
127
|
+
const cdateColumn = columns.find((col) => ["cdate", "created_at"].includes(col.name))?.name;
|
|
128
|
+
const editorDateColumn = columns.find((col) => ["editor_date", "updated_at"].includes(col.name))?.name;
|
|
129
|
+
const q1 = `select ${username} as author, u.login ${cdateColumn ? `,a.${cdateColumn} as cdate` : ""} ${editorDateColumn ? `,a.${editorDateColumn} as editor_date` : ""} from ${tableName} a
|
|
128
130
|
left join admin.users u on a.${authorIdColumn}=u.uid where a.${pk}=$1 limit 1`;
|
|
129
131
|
const data = pg.pk["admin.users"] && pk && tableName
|
|
130
132
|
? await pg
|