@opengis/fastify-table 1.4.87 → 1.4.88

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.4.87",
3
+ "version": "1.4.88",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -5,6 +5,14 @@ import pgClients from '../../../plugins/pg/pgClients.js';
5
5
  const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
6
6
  const username = 'coalesce(u.sur_name,\'\')||coalesce(\' \'||u.user_name,\'\') ||coalesce(\' \'||u.father_name,\'\')';
7
7
 
8
+ const pkList = {
9
+ comment: 'communication_id',
10
+ checklist: 'checklist_id',
11
+ file: 'file_id',
12
+ gallery: 'file_id',
13
+ reaction: 'reaction_id',
14
+ };
15
+
8
16
  /**
9
17
  * Дістає CRM для widget
10
18
  *
@@ -98,10 +106,21 @@ export default async function widgetGet({
98
106
 
99
107
  /* data */
100
108
  const time = [Date.now()];
101
- const { rows = [] } = await pg.query(q, [objectid, params.type === 'gallery' ? galleryExtList : null].filter((el) => el));
109
+ const { rows = [] } = await pg.query(q, [objectid, params.type === 'gallery' ? galleryExtList : null].filter(Boolean));
102
110
  rows.forEach(row => Object.assign(row, { username: row.username?.trim?.() || row.login }));
103
111
  time.push(Date.now());
104
112
 
113
+ /* reactions */
114
+ const widgetPkey = pkList[params.type];
115
+ if (params.type === 'comment' && widgetPkey) {
116
+ const reactions = rows.length && user.uid ? await pg.query('select json_object_agg(entity_id, reaction_type) from crm.reactions where entity_id=any($1) and created_by=$2', [rows.map(row => row[widgetPkey]), user.uid]).then((el) => el.rows?.[0]?.json_object_agg || {}) : {};
117
+ rows.filter(row => reactions[row[widgetPkey]]).forEach((row) => {
118
+ Object.assign(row, { reaction: reactions[row[widgetPkey]] });
119
+ });
120
+ }
121
+
122
+ time.push(Date.now());
123
+
105
124
  /* Object info */
106
125
  const { tableName } = pg.pk['log.table_changes'] ? await pg.query(
107
126
  'select entity_type as "tableName" from log.table_changes where entity_id=$1 limit 1',
@@ -128,7 +147,7 @@ export default async function widgetGet({
128
147
  }
129
148
 
130
149
  return reply.status(200).send({
131
- time: { data: time[1] - time[0] },
150
+ time: { data: time[2] - time[0] },
132
151
  rows,
133
152
  user: { uid: user?.uid, name: user?.user_name },
134
153
  data: { author: data?.author, cdate: data?.cdate, edate: data?.editor_date },