@opengis/fastify-table 1.4.84 → 1.4.86

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/index.js CHANGED
@@ -130,10 +130,22 @@ async function plugin(fastify, opt) {
130
130
  },
131
131
  body: ['PUT', 'POST'].includes(req.method) ? req.raw : undefined,
132
132
  });
133
- const resp = res.headers.get('content-type')?.includes('/json') ? await res.json() : await res.text();
134
133
  reply.headers(Object.fromEntries(res.headers));
135
134
  reply.status(res.status);
136
- reply.send(resp);
135
+ if (res.headers.get('content-type')?.startsWith?.('text/')) {
136
+ const resp = await res.text();
137
+ // reply.send(resp);
138
+ return resp;
139
+ }
140
+ if (res.headers.get('content-type')?.includes?.('/json')) {
141
+ const resp = await res.json();
142
+ // reply.send(resp);
143
+ return resp;
144
+ }
145
+ const blob = await res.blob();
146
+ const arrayBuffer = await blob.arrayBuffer();
147
+ const fileBuffer = Buffer.from(arrayBuffer);
148
+ return fileBuffer;
137
149
  });
138
150
  }
139
151
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.4.84",
3
+ "version": "1.4.86",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -124,7 +124,7 @@ COMMENT ON COLUMN crm.properties.table_name IS 'Таблиця';
124
124
  ALTER TABLE crm.properties ADD COLUMN IF NOT EXISTS object_id text;
125
125
  COMMENT ON COLUMN crm.properties.object_id IS 'ID Об''єкту';
126
126
  ALTER TABLE crm.properties ADD COLUMN IF NOT EXISTS property_key text;
127
- COMMENT ON COLUMN crm.properties.object_id IS 'Назва атрибуту';
127
+ COMMENT ON COLUMN crm.properties.property_key IS 'Назва атрибуту';
128
128
  ALTER TABLE crm.properties ADD COLUMN IF NOT EXISTS property_text text;
129
129
  COMMENT ON COLUMN crm.properties.property_text IS 'Текст';
130
130
  ALTER TABLE crm.properties ADD COLUMN IF NOT EXISTS property_int integer;
@@ -143,3 +143,13 @@ ALTER TABLE crm.properties ADD COLUMN IF NOT EXISTS cdate timestamp without time
143
143
  ALTER TABLE crm.properties ADD COLUMN IF NOT EXISTS files json;
144
144
 
145
145
  ALTER TABLE crm.properties ADD CONSTRAINT crm_properties_pkey PRIMARY KEY(property_id);
146
+
147
+ -- drop table if exists crm.reactions;
148
+ CREATE TABLE if not exists crm.reactions (
149
+ reaction_id text default next_id() PRIMARY KEY,
150
+ created_by text NOT NULL,
151
+ entity_id text NOT NULL,
152
+ reaction_type text NOT NULL check (reaction_type in ('like', 'love', 'hate', 'wow', 'sad', 'angry')),
153
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
154
+ FOREIGN KEY (user_id) REFERENCES admin.users(uid)
155
+ );
@@ -37,7 +37,7 @@ export default async function getForm({
37
37
 
38
38
  const form = tokenData?.form
39
39
  || hookData?.form
40
- || await getTemplate('table', table).then(el => el.form) || {};
40
+ || await getTemplate('table', table).then(el => el?.form) || {};
41
41
 
42
42
  if (!form) {
43
43
  return reply.status(404).send('form not found');
@@ -45,6 +45,10 @@ export default async function widgetDel(req, reply) {
45
45
  const { type, objectid, id } = params;
46
46
 
47
47
  if (!objectid) {
48
+ return reply.status(400).send('not enough params: object id');
49
+ }
50
+
51
+ if (!id && type !== 'reaction') {
48
52
  return reply.status(400).send('not enough params: id');
49
53
  }
50
54
 
@@ -60,6 +64,7 @@ export default async function widgetDel(req, reply) {
60
64
  checklist: `delete from crm.checklists where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'uid=$2'} and checklist_id=$3`,
61
65
  file: `update crm.files set file_status=3 where entity_id=$1 and ${!exists || isAdmin(req) ? '$2=$2' : 'uid=$2'} and file_id=$3 returning uploaded_name`,
62
66
  gallery: `update crm.files set file_status=3 where entity_id=$1 and ${!exists || isAdmin(req) ? '$2=$2' : 'uid=$2'} and file_id=$3 returning uploaded_name`,
67
+ reaction: `delete from crm.reactions where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'created_by=$2'} and $3=$3 returning reaction_type`,
63
68
  };
64
69
 
65
70
  const sql = sqls[type];
@@ -68,18 +73,23 @@ export default async function widgetDel(req, reply) {
68
73
  checklist: 'crm.checklists',
69
74
  file: 'crm.files',
70
75
  gallery: 'crm.files',
76
+ reaction: 'crm.reactions',
71
77
  }[type];
72
78
 
73
79
  if (!sql) {
74
80
  return reply.status(400).send('invalid widget type');
75
81
  }
76
82
 
77
- const { rows = [] } = await pg.query(sql, [objectid, user.uid, id]);
83
+ const { rows = [] } = await pg.query(sql, [objectid, user.uid, id || '']);
84
+
85
+ if (type === 'reaction') {
86
+ console.log('231131');
87
+ }
78
88
 
79
89
  await logChanges({
80
90
  pg,
81
91
  table,
82
- id,
92
+ id: type === 'reaction' ? objectid : id,
83
93
  data: rows[0],
84
94
  uid: user?.uid,
85
95
  type: 'DELETE',
@@ -87,7 +87,7 @@ export default async function widgetGet({
87
87
  where entity_id=$1 and file_status<>3 and ext = any($2) order by cdate desc`
88
88
  : `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, ismain,
89
89
  isverified, uid as author, file_status FROM crm.files c where entity_id=$1 and file_status<>3 and ext = any($2) order by cdate desc`,
90
-
90
+ reaction: 'SELECT count(*), reaction_type FROM crm.reactions c where entity_id=$1 group by reaction_type',
91
91
  };
92
92
 
93
93
  const q = sqls[params.type];
@@ -11,23 +11,25 @@ const tableList = {
11
11
  gallery: 'crm.files',
12
12
  file: 'crm.files',
13
13
  checklist: 'crm.checklists',
14
+ reaction: 'crm.reactions',
14
15
  };
15
16
  const pkList = {
16
17
  comment: 'communication_id',
17
18
  checklist: 'checklist_id',
18
19
  file: 'file_id',
19
20
  gallery: 'file_id',
21
+ reaction: 'reaction_id',
20
22
  };
21
23
 
22
24
  const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
23
25
 
24
26
  export default async function widgetSet(req, reply) {
25
27
  const {
26
- pg, params = {}, session = {}, headers = {}, body = {}, user = {},
28
+ pg, params = {}, headers = {}, body = {}, user = {},
27
29
  } = req;
28
30
  const { type, id, objectid } = params;
29
31
 
30
- if (!['comment', 'checklist', 'file', 'gallery'].includes(type)) {
32
+ if (!['comment', 'checklist', 'file', 'gallery', 'reaction'].includes(type)) {
31
33
  return reply.status(400).send('param type not valid');
32
34
  }
33
35
 
@@ -11,7 +11,7 @@ const tableSchema = {
11
11
  params: {
12
12
  type: 'object',
13
13
  properties: {
14
- // type: { type: 'string', pattern: '^([\\d\\w]+)$' },
14
+ type: { type: 'string', enum: ['gallery', 'file', 'checklist', 'history', 'comment', 'reaction'] },
15
15
  objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
16
16
  id: { type: 'string', pattern: '^([\\d\\w]+)$' },
17
17
  },