@opengis/fastify-table 2.0.148 → 2.0.149
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/config.d.ts.map +1 -1
- package/dist/config.js +7 -0
- package/dist/server/plugins/crud/funcs/dataInsert.js +11 -11
- package/dist/server/plugins/crud/funcs/utils/logChanges.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/utils/logChanges.js +6 -3
- package/dist/server/routes/widget/controllers/widget.get.d.ts +1 -1
- package/dist/server/routes/widget/controllers/widget.get.d.ts.map +1 -1
- package/dist/server/routes/widget/controllers/widget.get.js +27 -33
- package/package.json +1 -1
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,MAAM,KAA8D,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,MAAM,KAA8D,CAAC;AAgD3E,eAAe,MAAM,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -15,6 +15,13 @@ Object.assign(config, {
|
|
|
15
15
|
if (existsSync(`.env.local`)) {
|
|
16
16
|
dotenv.config({ path: `.env.local` }); // ! load .env.local
|
|
17
17
|
}
|
|
18
|
+
// example: bun server kamianske
|
|
19
|
+
if (process.cwd().split("\\").pop() &&
|
|
20
|
+
process.cwd().split("\\").pop() === "fastify-table" &&
|
|
21
|
+
process.argv[2] &&
|
|
22
|
+
existsSync(`.env.${process.argv[2]}`)) {
|
|
23
|
+
dotenv.config({ path: `.env.${process.argv[2]}` }); // ! for debug only
|
|
24
|
+
}
|
|
18
25
|
if (process.env?.NODE_ENV && existsSync(`.env.${process.env.NODE_ENV}`)) {
|
|
19
26
|
dotenv.config({ path: `.env.${process.env.NODE_ENV}` }); // ! load .env.{{production}} etc.
|
|
20
27
|
}
|
|
@@ -3,7 +3,7 @@ import getRedis from "../../redis/funcs/getRedis.js";
|
|
|
3
3
|
import pgClients from "../../pg/pgClients.js";
|
|
4
4
|
import getTemplate from "../../table/funcs/getTemplate.js";
|
|
5
5
|
import config from "../../../../config.js";
|
|
6
|
-
import logChanges from "./utils/logChanges.js";
|
|
6
|
+
// import logChanges from "./utils/logChanges.js";
|
|
7
7
|
import getInsertQuery from "./utils/getInsertQuery.js";
|
|
8
8
|
import logger from "../../logger/getLogger.js";
|
|
9
9
|
import extraData from "../../extra/extraData.js";
|
|
@@ -95,16 +95,16 @@ export default async function dataInsert({ id, table: table1, referer, data, pg:
|
|
|
95
95
|
Object.assign(res.rows[0], { [key]: parentRows.filter(Boolean) });
|
|
96
96
|
}));
|
|
97
97
|
}
|
|
98
|
-
await logChanges({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
98
|
+
// await logChanges({
|
|
99
|
+
// pg: client,
|
|
100
|
+
// table,
|
|
101
|
+
// tokenData,
|
|
102
|
+
// referer,
|
|
103
|
+
// data,
|
|
104
|
+
// id: id1,
|
|
105
|
+
// uid,
|
|
106
|
+
// type: "INSERT",
|
|
107
|
+
// });
|
|
108
108
|
if (config.redis && rclient?.status !== "end") {
|
|
109
109
|
rclient.incr(`pg:${client.options?.database}:${table}:crud`);
|
|
110
110
|
}
|
|
@@ -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;AA4B5D,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;;;;;;;;;;;;;;;;;;
|
|
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;AA4B5D,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;;;;;;;;;;;;;;;;;;UA6JA"}
|
|
@@ -49,10 +49,11 @@ export default async function logChanges({ pg, table: table1, tokenData, referer
|
|
|
49
49
|
.query(`insert into log.table_changes(change_date,change_type,change_user_id,entity_type,entity_id)
|
|
50
50
|
values(CURRENT_DATE, $1, $2, $3, $4) returning change_id`, [type, uid, table, id])
|
|
51
51
|
.then((el) => el.rows?.[0] || {});
|
|
52
|
-
const q = `select json_object_agg(entity_key, value_hash) from (
|
|
52
|
+
const q = `select json_object_agg(entity_key, json_build_object('hash',value_hash,'value',value_new)) from (
|
|
53
53
|
select
|
|
54
54
|
entity_key,
|
|
55
55
|
value_hash,
|
|
56
|
+
value_new,
|
|
56
57
|
( rank() over (partition by entity_key order by cdate desc) = 1 ) as is_latest
|
|
57
58
|
from log.table_changes_data
|
|
58
59
|
|
|
@@ -93,14 +94,16 @@ export default async function logChanges({ pg, table: table1, tokenData, referer
|
|
|
93
94
|
.map((el) => ({
|
|
94
95
|
change_id: changeId,
|
|
95
96
|
entity_key: el,
|
|
96
|
-
value_old: getValue(old?.[el], table),
|
|
97
|
+
value_old: getValue(old?.[el]?.value, table),
|
|
97
98
|
value_new: type === "DELETE" ? null : getValue(newObj?.[el], table),
|
|
98
99
|
value_hash: newObj?.[el]
|
|
99
100
|
? createHash("md5").update(JSON.stringify(newObj?.[el])).digest("hex")
|
|
100
101
|
: null,
|
|
101
102
|
uid,
|
|
102
103
|
}))
|
|
103
|
-
.filter((el) =>
|
|
104
|
+
.filter((el) => (newObj?.[el.entity_key] ||
|
|
105
|
+
getValue(old?.[el.entity_key]?.value, table)) &&
|
|
106
|
+
old?.[el.entity_key]?.hash !== el.value_hash);
|
|
104
107
|
const res = await Promise.all(changesData.map(async (el) => {
|
|
105
108
|
const insertQuery = `insert into log.table_changes_data (${Object.entries(el)
|
|
106
109
|
?.map((key) => `"${key[0]}"`)
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Дістає CRM для widget
|
|
3
3
|
*
|
|
4
4
|
*/
|
|
5
|
-
export default function widgetGet({ pg, user, params, query
|
|
5
|
+
export default function widgetGet({ pg, user, params, query }: any, reply: any): Promise<any>;
|
|
6
6
|
//# sourceMappingURL=widget.get.d.ts.map
|
|
@@ -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,
|
|
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,gBA+KX"}
|
|
@@ -23,7 +23,8 @@ const pkList = {
|
|
|
23
23
|
* Дістає CRM для widget
|
|
24
24
|
*
|
|
25
25
|
*/
|
|
26
|
-
export default async function widgetGet({ pg = pgClients.client, user = {}, params = {}, query = {}
|
|
26
|
+
export default async function widgetGet({ pg = pgClients.client, user = {}, params = {}, query = {} }, reply) {
|
|
27
|
+
const time = [Date.now()];
|
|
27
28
|
const param = user?.uid
|
|
28
29
|
? await getToken({
|
|
29
30
|
token: params.objectid,
|
|
@@ -43,8 +44,7 @@ export default async function widgetGet({ pg = pgClients.client, user = {}, para
|
|
|
43
44
|
left join admin.users u on u.uid=c.uid
|
|
44
45
|
where entity_id=$1 order by cdate desc`
|
|
45
46
|
: "select communication_id, entity_id, body, subject, cdate, uid from crm.communications where entity_id=$1 order by cdate desc",
|
|
46
|
-
history: `
|
|
47
|
-
SELECT change_id, entity_id, entity_type, change_type, change_date, a.change_user_id, a.uid, a.cdate, b.json_agg as changes,
|
|
47
|
+
history: `SELECT change_id, entity_id, entity_type, change_type, change_date, a.change_user_id, a.uid, a.cdate, b.json_agg as changes,
|
|
48
48
|
${username} as username, u.login, u.avatar
|
|
49
49
|
FROM log.table_changes a
|
|
50
50
|
left join admin.users u on a.change_user_id = u.uid
|
|
@@ -54,26 +54,12 @@ export default async function widgetGet({ pg = pgClients.client, user = {}, para
|
|
|
54
54
|
where change_id=a.change_id
|
|
55
55
|
)q
|
|
56
56
|
)b on 1=1
|
|
57
|
-
where b.json_agg is not null and (entity_id=$1 or entity_id in (
|
|
58
|
-
select communication_id
|
|
59
|
-
union all select checklist_id from crm.checklists where entity_id=$1
|
|
57
|
+
where a.change_type != 'INSERT' and b.json_agg is not null and (entity_id=$1 or entity_id in (
|
|
58
|
+
select communication_id from crm.communications where entity_id=$1
|
|
59
|
+
union all select checklist_id from crm.checklists where entity_id=$1
|
|
60
|
+
union all select file_id from crm.files where entity_id=$1)
|
|
60
61
|
)
|
|
61
|
-
|
|
62
|
-
union all
|
|
63
|
-
select change_id, entity_id, entity_type, change_type, change_date, a.change_user_id, a.uid, a.cdate, b.json_agg as changes,
|
|
64
|
-
${username} as username, u.login, u.avatar
|
|
65
|
-
FROM log.table_changes a
|
|
66
|
-
left join admin.users u on a.change_user_id = u.uid
|
|
67
|
-
left join lateral(
|
|
68
|
-
select json_agg(o) from (
|
|
69
|
-
select json_object_agg(entity_key, coalesce(value_new, value_old)) as o from log.table_changes_data
|
|
70
|
-
where change_id=a.change_id and entity_key not in ('uid', 'file_status', 'editor_id', 'cdate', 'editor_date', 'entity_id')
|
|
71
|
-
)q
|
|
72
|
-
)b on 1=1
|
|
73
|
-
where a.change_type in ('INSERT', 'DELETE') and a.entity_id in (select file_id from crm.files where entity_id=$1)
|
|
74
|
-
limit 100
|
|
75
|
-
|
|
76
|
-
)q order by cdate desc limit 100`,
|
|
62
|
+
order by cdate desc limit 100`,
|
|
77
63
|
checklist: pg.pk["admin.users"]
|
|
78
64
|
? `SELECT checklist_id, entity_id, subject, is_done, done_date, c.uid, c.cdate, ${username} as username, u.login, u.avatar
|
|
79
65
|
FROM crm.checklists c
|
|
@@ -102,9 +88,11 @@ export default async function widgetGet({ pg = pgClients.client, user = {}, para
|
|
|
102
88
|
if (!q) {
|
|
103
89
|
return reply.status(400).send("invalid widget type");
|
|
104
90
|
}
|
|
105
|
-
/*
|
|
106
|
-
const
|
|
107
|
-
|
|
91
|
+
/* rows */
|
|
92
|
+
const rows = await pg
|
|
93
|
+
.query(q, [objectid, params.type === "gallery" ? galleryExtList : null].filter(Boolean))
|
|
94
|
+
.then((el) => el.rows || []);
|
|
95
|
+
time.push(Date.now());
|
|
108
96
|
rows.forEach((row) => Object.assign(row, { username: row.username?.trim?.() || row.login }));
|
|
109
97
|
/* reactions */
|
|
110
98
|
const widgetPkey = pkList[params.type];
|
|
@@ -121,26 +109,32 @@ export default async function widgetGet({ pg = pgClients.client, user = {}, para
|
|
|
121
109
|
});
|
|
122
110
|
}
|
|
123
111
|
/* Object info */
|
|
124
|
-
const
|
|
112
|
+
const tableName = pg.pk["log.table_changes"]
|
|
125
113
|
? await pg
|
|
126
|
-
.query(
|
|
127
|
-
.then((el) => el.rows?.[0]
|
|
114
|
+
.query("select entity_type from log.table_changes where entity_id=$1 limit 1", [objectid])
|
|
115
|
+
.then((el) => el.rows?.[0]?.entity_type)
|
|
116
|
+
: null;
|
|
117
|
+
const { pk, columns = [] } = tableName
|
|
118
|
+
? await getMeta({ pg, table: tableName })
|
|
128
119
|
: {};
|
|
129
|
-
const { pk, columns = [] } = await getMeta({ pg, table: tableName });
|
|
130
120
|
const authorIdColumn = columns.find((col) => ["uid", "created_by"].includes(col.name))?.name;
|
|
131
|
-
if (!pk &&
|
|
121
|
+
if (!pk &&
|
|
122
|
+
params.type === "history" &&
|
|
123
|
+
process.env.NODE_ENV !== "test" &&
|
|
124
|
+
!process.env.VITEST) {
|
|
132
125
|
return reply.status(404).send("log table not found");
|
|
133
126
|
}
|
|
134
127
|
const q1 = `select ${username} as author, u.login, a.cdate, a.editor_date from ${tableName} a
|
|
135
128
|
left join admin.users u on a.${authorIdColumn}=u.uid where a.${pk}=$1 limit 1`;
|
|
136
129
|
const data = pg.pk["admin.users"] && pk && tableName
|
|
137
130
|
? await pg
|
|
138
|
-
.query(
|
|
131
|
+
.query(q1, [
|
|
139
132
|
objectid,
|
|
140
133
|
params.type === "gallery" ? galleryExtList : null,
|
|
141
|
-
].filter(
|
|
134
|
+
].filter(Boolean))
|
|
142
135
|
.then((el) => el.rows?.[0] || {})
|
|
143
136
|
: {};
|
|
137
|
+
time.push(Date.now());
|
|
144
138
|
if (query.debug && user?.user_type === "admin") {
|
|
145
139
|
return {
|
|
146
140
|
q,
|
|
@@ -151,7 +145,7 @@ export default async function widgetGet({ pg = pgClients.client, user = {}, para
|
|
|
151
145
|
};
|
|
152
146
|
}
|
|
153
147
|
return reply.status(200).send({
|
|
154
|
-
time: { data:
|
|
148
|
+
time: { rows: time[1] - time[0], data: time[2] - time[1] },
|
|
155
149
|
rows,
|
|
156
150
|
user: { uid: user?.uid, name: user?.user_name },
|
|
157
151
|
data: {
|