@opengis/fastify-table 1.1.55 → 1.1.57

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.
Files changed (260) hide show
  1. package/README.md +26 -26
  2. package/config.js +10 -10
  3. package/index.js +27 -14
  4. package/package.json +10 -6
  5. package/server/migrations/log.sql +80 -80
  6. package/{cron → server/plugins/cron}/funcs/addCron.js +15 -19
  7. package/server/plugins/cron/index.js +6 -0
  8. package/{crud → server/plugins/crud}/funcs/dataDelete.js +3 -1
  9. package/{crud → server/plugins/crud}/funcs/dataInsert.js +3 -0
  10. package/{crud → server/plugins/crud}/funcs/dataUpdate.js +3 -1
  11. package/{crud → server/plugins/crud}/funcs/getAccess.js +5 -3
  12. package/{crud → server/plugins/crud}/funcs/getOpt.js +2 -0
  13. package/{crud → server/plugins/crud}/funcs/getToken.js +30 -27
  14. package/{crud → server/plugins/crud}/funcs/isFileExists.js +13 -13
  15. package/{crud → server/plugins/crud}/funcs/setOpt.js +3 -0
  16. package/{crud → server/plugins/crud}/funcs/setToken.js +4 -1
  17. package/{crud → server/plugins/crud}/funcs/utils/getFolder.js +2 -1
  18. package/{crud → server/plugins/crud}/funcs/utils/logChanges.js +2 -2
  19. package/server/plugins/crud/index.js +23 -0
  20. package/{hook → server/plugins/hook}/funcs/addHook.js +1 -1
  21. package/{hook → server/plugins/hook}/funcs/applyHook.js +2 -2
  22. package/{cron/controllers/utils/cronList.js → server/plugins/hook/hookList.js} +1 -1
  23. package/server/plugins/hook/index.js +8 -0
  24. package/{logger → server/plugins/logger}/createFileStream.js +2 -2
  25. package/{logger → server/plugins/logger}/getLogger.js +1 -1
  26. package/{migration → server/plugins/migration/funcs}/exec.migrations.js +1 -1
  27. package/server/plugins/migration/index.js +7 -0
  28. package/{pg → server/plugins/pg}/funcs/getPG.js +3 -3
  29. package/{pg → server/plugins/pg}/funcs/getPGAsync.js +3 -3
  30. package/{pg → server/plugins/pg}/funcs/init.js +2 -4
  31. package/{pg → server/plugins/pg}/index.js +5 -14
  32. package/{pg → server/plugins/pg}/pgClients.js +2 -1
  33. package/{policy → server/plugins/policy}/funcs/checkPolicy.js +1 -1
  34. package/{crud/controllers/utils → server/plugins/policy/funcs}/checkXSS.js +1 -4
  35. package/{policy → server/plugins/policy}/index.js +0 -2
  36. package/{policy/funcs → server/plugins/policy}/sqlInjection.js +1 -1
  37. package/{crud/controllers/utils → server/plugins/policy}/xssInjection.js +72 -72
  38. package/{redis → server/plugins/redis}/funcs/getRedis.js +24 -23
  39. package/{redis → server/plugins/redis}/funcs/redisClients.js +1 -0
  40. package/{redis → server/plugins/redis}/index.js +2 -6
  41. package/{table → server/plugins/table}/funcs/getFilterSQL/index.js +3 -1
  42. package/{table/controllers/utils → server/plugins/table/funcs}/getSelectMeta.js +1 -10
  43. package/{table/controllers/utils → server/plugins/table/funcs}/getTemplate.js +2 -1
  44. package/{table/controllers/utils → server/plugins/table/funcs}/getTemplatePath.js +3 -3
  45. package/{table/controllers/utils → server/plugins/table/funcs}/getTemplates.js +2 -1
  46. package/{table/controllers/utils → server/plugins/table/funcs}/gisIRColumn.js +4 -7
  47. package/{table → server/plugins/table}/funcs/metaFormat/getSelectVal.js +4 -2
  48. package/{table → server/plugins/table}/funcs/metaFormat/index.js +3 -1
  49. package/server/plugins/table/index.js +13 -0
  50. package/{util → server/plugins/util/funcs}/eventStream.js +1 -0
  51. package/server/plugins/util/index.js +7 -0
  52. package/{cron → server/routes/cron}/controllers/cronApi.js +22 -22
  53. package/{cron → server/routes/cron}/index.js +5 -3
  54. package/{crud → server/routes/crud}/controllers/deleteCrud.js +2 -2
  55. package/{crud → server/routes/crud}/controllers/insert.js +5 -3
  56. package/{crud → server/routes/crud}/controllers/update.js +3 -3
  57. package/server/routes/crud/index.js +19 -0
  58. package/{util → server/routes/logger}/controllers/logger.file.js +5 -5
  59. package/{util → server/routes/logger}/controllers/utils/checkUserAccess.js +1 -1
  60. package/{util → server/routes/logger}/controllers/utils/getRootDir.js +4 -3
  61. package/server/routes/logger/index.js +15 -0
  62. package/{util → server/routes/properties}/controllers/properties.add.js +19 -20
  63. package/server/routes/properties/controllers/properties.get.js +17 -0
  64. package/{util → server/routes/properties}/index.js +5 -8
  65. package/{table → server/routes/table}/controllers/card.js +3 -5
  66. package/{table → server/routes/table}/controllers/data.js +4 -10
  67. package/{table → server/routes/table}/controllers/filter.js +3 -4
  68. package/{table → server/routes/table}/controllers/form.js +1 -1
  69. package/{table → server/routes/table}/controllers/search.js +15 -17
  70. package/{table → server/routes/table}/controllers/suggest.js +15 -10
  71. package/{table → server/routes/table}/controllers/table.js +5 -7
  72. package/{table → server/routes/table}/index.js +1 -10
  73. package/{table → server/routes/table}/schema.js +1 -1
  74. package/{util → server/routes/util}/controllers/next.id.js +4 -4
  75. package/server/routes/util/index.js +11 -0
  76. package/utils.js +58 -50
  77. package/.eslintrc.cjs +0 -44
  78. package/.gitlab-ci.yml +0 -18
  79. package/Changelog.md +0 -352
  80. package/cron/schema.js +0 -8
  81. package/crud/index.js +0 -31
  82. package/crud/schema.js +0 -11
  83. package/docs/.vitepress/abbr.mjs +0 -26
  84. package/docs/.vitepress/config.mjs +0 -127
  85. package/docs/.vitepress/navigation.mjs +0 -82
  86. package/docs/.vitepress/theme/Layout.vue +0 -17
  87. package/docs/.vitepress/theme/components/NavigationLinks.vue +0 -102
  88. package/docs/.vitepress/theme/components/Panzoom.vue +0 -169
  89. package/docs/.vitepress/theme/index.mjs +0 -15
  90. package/docs/.vitepress/theme/style.scss +0 -163
  91. package/docs/abbr.json +0 -4
  92. package/docs/api/cron/cronApi.md +0 -56
  93. package/docs/api/crud/deleteCrud.md +0 -58
  94. package/docs/api/crud/insert.md +0 -82
  95. package/docs/api/crud/update.md +0 -85
  96. package/docs/api/index.md +0 -47
  97. package/docs/api/notification/testEmail.md +0 -91
  98. package/docs/api/table/card.md +0 -73
  99. package/docs/api/table/data.md +0 -134
  100. package/docs/api/table/export.md +0 -60
  101. package/docs/api/table/filter.md +0 -104
  102. package/docs/api/table/form.md +0 -126
  103. package/docs/api/table/search.md +0 -123
  104. package/docs/api/table/suggest.md +0 -156
  105. package/docs/api/table/table.md +0 -107
  106. package/docs/api/user/user.cls.id.md +0 -77
  107. package/docs/api/user/user.cls.md +0 -49
  108. package/docs/api/user/user.cls.post.md +0 -62
  109. package/docs/api/user/user.info.md +0 -37
  110. package/docs/api/utils/logger.file.md +0 -61
  111. package/docs/api/utils/next.id.md +0 -34
  112. package/docs/api/utils/properties.add.md +0 -127
  113. package/docs/api/utils/properties.get.md +0 -73
  114. package/docs/api/utils/status.monitor.md +0 -36
  115. package/docs/api/widget/widget.del.md +0 -76
  116. package/docs/api/widget/widget.get.md +0 -233
  117. package/docs/api/widget/widget.set.md +0 -88
  118. package/docs/db/admin.md +0 -947
  119. package/docs/db/crm.md +0 -564
  120. package/docs/db/index.md +0 -9
  121. package/docs/db/log.md +0 -204
  122. package/docs/hook/card/afterCard.md +0 -20
  123. package/docs/hook/card/preCard.md +0 -25
  124. package/docs/hook/data/afterData.md +0 -26
  125. package/docs/hook/data/preData.md +0 -26
  126. package/docs/hook/deleteCrud/afterDelete.md +0 -21
  127. package/docs/hook/deleteCrud/preDelete.md +0 -26
  128. package/docs/hook/form/afterForm.md +0 -19
  129. package/docs/hook/form/preForm.md +0 -26
  130. package/docs/hook/getTemplate/afterTemplate.md +0 -24
  131. package/docs/hook/getTemplate/preTemplate.md +0 -29
  132. package/docs/hook/index.md +0 -45
  133. package/docs/hook/insert/afterInsert.md +0 -41
  134. package/docs/hook/insert/preInsert.md +0 -25
  135. package/docs/hook/table/afterTable.md +0 -20
  136. package/docs/hook/table/preTable.md +0 -25
  137. package/docs/hook/update/afterUpdate.md +0 -41
  138. package/docs/hook/update/preUpdate.md +0 -25
  139. package/docs/index.md +0 -42
  140. package/docs/public/fastify-dark.svg +0 -4
  141. package/docs/public/fastify.svg +0 -1
  142. package/docs/public/logo-short-dark.svg +0 -12
  143. package/docs/public/logo-short.svg +0 -11
  144. package/docs/public/logo.svg +0 -19
  145. package/docs/readme/index.md +0 -121
  146. package/docs/templates/card.md +0 -83
  147. package/docs/templates/cls.md +0 -29
  148. package/docs/templates/filters.md +0 -91
  149. package/docs/templates/forms.md +0 -139
  150. package/docs/templates/image.png +0 -0
  151. package/docs/templates/index.md +0 -28
  152. package/docs/templates/select.md +0 -90
  153. package/docs/templates/table.md +0 -162
  154. package/docs/utils/cron/addCron.md +0 -29
  155. package/docs/utils/crud/dataInsert.md +0 -52
  156. package/docs/utils/crud/dataUpdate.md +0 -53
  157. package/docs/utils/crud/getOpt.md +0 -34
  158. package/docs/utils/crud/isFileExists.md +0 -38
  159. package/docs/utils/crud/setOpt.md +0 -38
  160. package/docs/utils/hook/addHook.md +0 -74
  161. package/docs/utils/hook/applyHook.md +0 -64
  162. package/docs/utils/index.md +0 -48
  163. package/docs/utils/notification/addNotification.md +0 -28
  164. package/docs/utils/notification/notification.md +0 -41
  165. package/docs/utils/pg/autoIndex.md +0 -22
  166. package/docs/utils/pg/getMeta.md +0 -59
  167. package/docs/utils/pg/getPG.md +0 -34
  168. package/docs/utils/pg/init.md +0 -30
  169. package/docs/utils/pg/pg.md +0 -70
  170. package/docs/utils/redis/getRedis.md +0 -36
  171. package/docs/utils/redis/rclient.md +0 -74
  172. package/docs/utils/table/getForm.md +0 -69
  173. package/docs/utils/table/getMeta.md +0 -56
  174. package/docs/utils/table/getSelect.md +0 -39
  175. package/docs/utils/table/getSelectMeta.md +0 -47
  176. package/docs/utils/table/getTable.md +0 -78
  177. package/helper.js +0 -30
  178. package/module/core/select/core.user_mentioned.sql +0 -2
  179. package/module/test/cls/itree.composition.json +0 -26
  180. package/module/test/table/test.rest_zone.table.json +0 -266
  181. package/notification/controllers/readNotifications.js +0 -27
  182. package/notification/controllers/testEmail.js +0 -46
  183. package/notification/controllers/userNotifications.js +0 -61
  184. package/notification/controllers/utils/pin-m-ty-media-record-outline+303070.png +0 -0
  185. package/notification/funcs/addNotification.js +0 -21
  186. package/notification/funcs/sendNotification.js +0 -112
  187. package/notification/funcs/utils/sendEmail.js +0 -39
  188. package/notification/index.js +0 -18
  189. package/notification/schema.js +0 -10
  190. package/server.js +0 -26
  191. package/table/controllers/utils/getTemplate_old.js +0 -28
  192. package/test/api/applyHook.test.js +0 -95
  193. package/test/api/crud.test.js +0 -89
  194. package/test/api/crud.xss.test.js +0 -80
  195. package/test/api/notification.test.js +0 -48
  196. package/test/api/suggest.test.js +0 -66
  197. package/test/api/table.test.js +0 -134
  198. package/test/api/user.test.js +0 -85
  199. package/test/api/widget.test.js +0 -117
  200. package/test/config.example +0 -18
  201. package/test/funcs/pg.test.js +0 -34
  202. package/test/funcs/redis.test.js +0 -19
  203. package/test/helper/formatDate.test.js +0 -62
  204. package/test/templates/cls/itree.quality_condition.json +0 -20
  205. package/test/templates/cls/itree.recommend copy.json +0 -26
  206. package/test/templates/cls/itree.recommend.json +0 -26
  207. package/test/templates/cls/itree.type_plant.json +0 -65
  208. package/test/templates/cls/test.json +0 -10
  209. package/test/templates/form/cp_building.form.json +0 -33
  210. package/test/templates/select/account_id.json +0 -4
  211. package/test/templates/select/account_id.sql +0 -1
  212. package/test/templates/select/atu.nsdi.ato_level.json +0 -4
  213. package/test/templates/select/atu.nsdi.ato_level.sql +0 -11
  214. package/test/templates/select/contact_id.sql +0 -1
  215. package/test/templates/select/storage.data.json +0 -3
  216. package/test/templates/select/storage.data.sql +0 -1
  217. package/test/templates/select/test.storage.data.json +0 -4
  218. package/test/templates/select/test.storage.data.sql +0 -1
  219. package/test/templates/select/test.suggest.ato_new.json +0 -4
  220. package/test/templates/select/test.suggest.ato_new.sql +0 -26
  221. package/test/templates/select/test.suggest.data.json +0 -5
  222. package/test/templates/select/test.suggest.data.sql +0 -1
  223. package/test/templates/select/test.suggest.parent.sql +0 -2
  224. package/test/templates/table/gis.dataset.table.json +0 -21
  225. package/test/templates/table/green_space.table.json +0 -383
  226. package/test/templates/table/service.json +0 -18
  227. package/user/controllers/user.cls.id.js +0 -14
  228. package/user/controllers/user.cls.js +0 -71
  229. package/user/controllers/user.cls.post.js +0 -52
  230. package/user/controllers/user.info.js +0 -17
  231. package/user/index.js +0 -17
  232. package/user/schema.js +0 -17
  233. package/util/controllers/properties.get.js +0 -17
  234. package/util/schema.js +0 -19
  235. package/widget/controllers/utils/historyFormat.js +0 -76
  236. package/widget/controllers/utils/obj2db.js +0 -13
  237. package/widget/controllers/widget.del.js +0 -41
  238. package/widget/controllers/widget.get.js +0 -96
  239. package/widget/controllers/widget.set.js +0 -74
  240. package/widget/index.js +0 -40
  241. /package/{hook/funcs/hookList.js → server/plugins/cron/cronList.js} +0 -0
  242. /package/{logger → server/plugins/logger}/getHooks.js +0 -0
  243. /package/{logger → server/plugins/logger}/labels.js +0 -0
  244. /package/{logger → server/plugins/logger}/logger.test.api.js +0 -0
  245. /package/{logger → server/plugins/logger}/serializers.js +0 -0
  246. /package/{pg → server/plugins/pg}/funcs/autoIndex.js +0 -0
  247. /package/{pg → server/plugins/pg}/funcs/getMeta.js +0 -0
  248. /package/{pg → server/plugins/pg}/funcs/pgClients.js +0 -0
  249. /package/{redis → server/plugins/redis}/client.js +0 -0
  250. /package/{table/controllers/utils → server/plugins/table/funcs}/addTemplateDir.js +0 -0
  251. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/formatValue.js +0 -0
  252. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getCustomQuery.js +0 -0
  253. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getFilterQuery.js +0 -0
  254. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getOptimizedQuery.js +0 -0
  255. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getTableSql.js +0 -0
  256. /package/{table/controllers/utils → server/plugins/table/funcs}/getSelect.js +0 -0
  257. /package/{table/controllers/utils → server/plugins/table/funcs}/loadTemplate.js +0 -0
  258. /package/{table/controllers/utils → server/plugins/table/funcs}/loadTemplatePath.js +0 -0
  259. /package/{table/controllers/utils → server/plugins/table/funcs}/userTemplateDir.js +0 -0
  260. /package/{util → server/routes/util}/controllers/status.monitor.js +0 -0
@@ -1,76 +0,0 @@
1
- import { readdir } from 'fs/promises';
2
- import { existsSync, readFileSync } from 'fs';
3
-
4
- // import getTemplate from '../../../table/controllers/utils/getTemplate.js';
5
- import getSelect from '../../../table/controllers/utils/getSelect.js';
6
-
7
- const dbData = {};
8
-
9
- // from config??
10
- const allTemplates = { table: {} };
11
-
12
- const historyQ = `select nspname||'.'||relname as table_name, json_agg(json_build_object('name',attname, 'title',coalesce(col_description(attrelid, attnum),attname))) as columns
13
- from pg_attribute a
14
- left join pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
15
- JOIN pg_class AS i
16
- ON i.oid = a.attrelid
17
- JOIN pg_namespace AS NS ON i.relnamespace = NS.OID
18
- where a.attnum > 0
19
- and not a.attisdropped
20
- group by nspname||'.'||relname`;
21
-
22
- export default async function historyFormat(rows, table, pg) {
23
- if (!rows?.[0]?.changes) return rows; // old structure
24
- // on startup
25
- if (!allTemplates.table.length) {
26
- const templateDir = './server/templates/table';
27
- const templates = existsSync(templateDir) ? await readdir(templateDir) : [];
28
- templates.forEach((template) => {
29
- const body = JSON.parse(readFileSync(`${templateDir}/${template}`) || '{}');
30
- Object.assign(allTemplates.table, { [template]: body });
31
- });
32
- }
33
-
34
- const progrid = Object.keys(allTemplates.table).find((key) => key.replace('.json', '') === table);
35
- if (!progrid) return rows;
36
- // const body = await getTemplate('table', progrid);
37
- const body = allTemplates.table[progrid];
38
- const tableName = body?.table || table;
39
- if (!tableName) return rows;
40
-
41
- // get DB column description
42
- if (!dbData?.[body.table]?.length) {
43
- const { rows: rows1 } = await pg.query(historyQ);
44
- rows1.forEach((row) => {
45
- dbData[row.table_name] = row.columns;
46
- });
47
- }
48
-
49
- // rewrite!!!
50
- await Promise.all(rows?.map(async (op) => {
51
- op.changes?.map(async (el) => {
52
- const col = body.colModel.filter((col1) => col1.name === el.attr)[0] || dbData[body?.table]?.find((col1) => col1.name === el.attr);
53
- if (el.attr === 'geom') {
54
- el.title = 'Геометрія';
55
- }
56
- el.title = col?.ua || col?.title || el.attr;
57
- if (!col) return;
58
- el.type = col.type;
59
- el.format = col.format;
60
- const select = col.data || col.option || col.select;
61
-
62
- // getSelect not equals to node
63
- if (select && false) {
64
- el.select = select;
65
- const cls = await getSelect(select, {
66
- val: [el.old, el.new],
67
- });
68
-
69
- el.oldf = cls[0] || el.old;
70
- el.newf = cls[1] || el.new;
71
- }
72
- });
73
- }));
74
-
75
- return rows;
76
- }
@@ -1,13 +0,0 @@
1
- export default function obj2db(data, nonexistCol) {
2
- if (
3
- typeof data !== 'object'
4
- || Array.isArray(data)
5
- || !Object.keys(data || {}).length
6
- ) return { error: 'invalid data type' };
7
-
8
- const columns = Object.keys(data)?.filter((key) => !nonexistCol.includes(key));
9
- // const columns = existColumns?.filter((col) => data[col] || data?.[col] === 0);
10
- const args = columns?.map((col) => data[col]);
11
-
12
- return { columns, args, error: !columns?.length ? 'nothing to process' : undefined };
13
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * Дістає CRM дані для vue хешує ідентифікатори, підтягує селекти
3
- *
4
- * @method DELETE
5
- * @summary CRM дані для обраного віджета.
6
- * @priority 2
7
- * @tag table
8
- * @type api
9
- * @requires setTokenById
10
- * @requires getSelect
11
- * @param {String} id Ідентифікатор для хешування
12
- * @param {Any} sql Використовується для повернення sql запиту
13
- * @param {String} type Тип для хешування даних
14
- * @errors 400, 500
15
- * @returns {Number} status Номер помилки
16
- * @returns {String|Object} error Опис помилки
17
- * @returns {String|Object} message Повідомлення про успішне виконання або об'єкт з параметрами
18
- */
19
-
20
- export default async function widgetDel({
21
- pg, params = {}, session = {},
22
- }) {
23
- const { user = {} } = session.passport || {};
24
- if (!user.uid) return { error: 'access restricted', status: 403 };
25
- const { type, objectid, id } = params;
26
-
27
- if (!objectid) return { error: 'id required', status: 400 };
28
-
29
- const sqls = {
30
- comment: 'delete from crm.communications where entity_id=$1 and uid=$2 and communication_id=$3',
31
- checklist: 'delete from crm.checklists where entity_id=$1 and uid=$2 and checklist_id=$3',
32
- file: 'update crm.files set file_status=3 where entity_id=$1 and uid=$2 and file_id=$3',
33
- gallery: 'update crm.files set file_status=3 where entity_id=$1 and uid=$2 and file_id=$3',
34
- };
35
- const sql = sqls[type];
36
- if (!sql) return { error: 'type not valid', status: 401 };
37
-
38
- await pg.query(sql, [objectid, user.uid, id]);
39
- return { data: { id }, user: { uid: user.uid, name: user.user_name } };
40
-
41
- }
@@ -1,96 +0,0 @@
1
- import getToken from '../../crud/funcs/getToken.js';
2
- import getMeta from '../../pg/funcs/getMeta.js';
3
- import historyFormat from './utils/historyFormat.js';
4
-
5
- const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
6
-
7
- /**
8
- * Дістає CRM для widget
9
- *
10
- */
11
-
12
- export default async function widgetGet({
13
- pg, session = {}, params = {}, query = {},
14
- }) {
15
- const { user = {} } = session.passport || {};
16
-
17
- const param = user?.uid ? await getToken({
18
- token: params.objectid, mode: 'w', uid: user.uid,
19
- }) : null;
20
-
21
- const objectid = param ? JSON.parse(param)?.id : params.objectid;
22
-
23
- if (!objectid) return { error: 'id required', status: 400 };
24
-
25
- const sqls = {
26
- comment: pg.pk['admin.users']
27
- ? `select communication_id, entity_id, body, subject, c.cdate, c.uid,
28
- coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username, avatar
29
- from crm.communications c left join admin.users u on u.uid=c.uid where entity_id=$1 order by cdate desc`
30
- : 'select communication_id, entity_id, body, subject, cdate, uid from crm.communications where entity_id=$1 order by cdate desc',
31
-
32
- history: `SELECT b.change_data_id, change_id, entity_id, entity_type, change_type, change_date, uid, cdate, b.entity_key, b.value_new, b.value_old FROM log.table_changes a
33
- left join lateral(
34
- select change_data_id, entity_key, value_new, value_old from log.table_changes_data where change_id=a.change_id
35
- )b on 1=1
36
- where (entity_id=$1 or entity_id in (
37
- select communication_id as comments from crm.communications where entity_id=$1
38
- union all select file_id from crm.files where entity_id=$1
39
- union all select checklist_id from crm.checklists where entity_id=$1)
40
- ) and b.change_data_id is not null order by cdate desc limit 100`,
41
-
42
- checklist: pg.pk['admin.users']
43
- ? `SELECT checklist_id, entity_id, subject, is_done, done_date, c.uid, c.cdate, coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username,
44
- avatar FROM crm.checklists c left join admin.users u on u.uid=c.uid where entity_id=$1 order by cdate desc`
45
- : 'SELECT checklist_id, entity_id, subject, is_done, done_date, uid, cdate FROM crm.checklists where entity_id=$1 order by cdate desc',
46
-
47
- file: pg.pk['admin.users']
48
- ? `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
49
- coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username, isverified,
50
- avatar, c.uid as author, file_status FROM crm.files c left join admin.users u on u.uid=c.uid
51
- where entity_id=$1 and file_status<>3 order by cdate desc`
52
- : `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, uid, cdate, file_type, ismain,
53
- isverified, uid as author, file_status FROM crm.files c where entity_id=$1 and file_status<>3 order by cdate desc`,
54
- gallery: pg.pk['admin.users']
55
- ? `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
56
- coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username, isverified,
57
- avatar, c.uid as author, file_status FROM crm.files c left join admin.users u on u.uid=c.uid
58
- where entity_id=$1 and file_status<>3 and ext = any($2) order by cdate desc`
59
- : `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, ismain,
60
- 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`,
61
-
62
- };
63
- const sql = sqls[params.type];
64
- if (!sql) {
65
- return { error: 'param type not valid', status: 400 };
66
- }
67
-
68
-
69
- /* data */
70
- const time = [Date.now()];
71
- const { rows } = await pg.query(sql, [objectid, params.type === 'gallery' ? galleryExtList : null].filter((el) => el));
72
- time.push(Date.now());
73
-
74
- /* Object info */
75
- const { tableName } = pg.pk['log.table_changes'] ? await pg.one('select entity_type as "tableName" from log.table_changes where entity_id=$1 limit 1', [objectid]) : {};
76
- const { pk } = await getMeta({ table: tableName });
77
-
78
- const q = tableName && pg.pk['admin.users'] ? `select coalesce(b.user_name,'')||coalesce(' '||b.sur_name,'') as author, a.cdate, a.editor_date from ${tableName} a
79
- left join admin.users b on a.uid=b.uid where a.${pk}=$1 limit 1` : undefined;
80
- const data = pk && q ? await pg.one(q, [objectid]) : {};
81
-
82
- if (query.debug && user?.user_type === 'admin') {
83
- return {
84
- sql, type: params.type, q, id: objectid, data,
85
- };
86
- }
87
-
88
- time.push(Date.now());
89
- return {
90
- time: { data: time[1] - time[0], format: time[2] - time[1] },
91
- rows: params.type === 'history' ? await historyFormat(rows, tableName, pg) : rows,
92
- user: { uid: user?.uid, name: user?.user_name },
93
- data: { author: data?.author, cdate: data?.cdate, edate: data?.editor_date },
94
- objectid: params.objectid,
95
- };
96
- }
@@ -1,74 +0,0 @@
1
- import path from 'path';
2
-
3
- import {
4
- getMeta, dataInsert, dataUpdate, applyHook,
5
- } from '../../utils.js';
6
-
7
- const tableList = {
8
- comment: 'crm.communications',
9
- checklist: 'crm.checklists',
10
- };
11
- const pkList = {
12
- comment: 'communication_id',
13
- checklist: 'checklist_id',
14
- };
15
-
16
- const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
17
-
18
- export default async function widgetSet(req) {
19
- const {
20
- pg, params = {}, session = {}, body = {}, funcs, log,
21
- } = req;
22
- const { user = {} } = session.passport || {};
23
- const { type, id, objectid } = params;
24
- if (!['comment', 'checklist', 'file', 'gallery'].includes(type)) return { message: 'param type not valid', status: 400 };
25
- if (!objectid) return { message: 'id required', status: 400 };
26
-
27
- const table = tableList[type];
28
-
29
-
30
- if (['gallery', 'file'].includes(type)) {
31
- const file = await funcs.uploadMultiPart(req);
32
- const extName = path.extname(file.filepath).slice(1).toLowerCase();
33
-
34
- const data = {
35
- uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
36
- file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
37
- ext: extName,
38
- size: file?.size,
39
- file_status: 1,
40
- uid: user?.uid || 1,
41
- entity_id: objectid,
42
- };
43
-
44
- if (type === 'gallery' && !galleryExtList.includes(extName.toLowerCase())) {
45
- return { message: 'invalid file extension', status: 400 };
46
- }
47
-
48
- const { rows = [] } = await dataInsert({
49
- table: 'crm.files', data, uid: user?.uid,
50
- });
51
- return {
52
- rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
53
- };
54
- }
55
- const { pk } = await getMeta({ pg, table });
56
- if (!pk) return { message: 'table not found', status: 404 };
57
-
58
- const data = { ...body, uid: user?.uid, entity_id: objectid };
59
-
60
- await applyHook('onWidgetSet', {
61
- link: req.path, session, log, type, payload: data,
62
- });
63
- const result = id
64
- ? await dataUpdate({
65
- table, data, id, uid: user?.uid,
66
- })
67
- : await dataInsert({
68
- table, data, uid: user?.uid,
69
- });
70
-
71
- return {
72
- rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
73
- };
74
- }
package/widget/index.js DELETED
@@ -1,40 +0,0 @@
1
- import widgetDel from './controllers/widget.del.js';
2
- import widgetSet from './controllers/widget.set.js';
3
- import widgetGet from './controllers/widget.get.js';
4
-
5
- const tableSchema = {
6
- params: {
7
- // type: { type: 'string', pattern: '^([\\d\\w]+)$' },
8
- objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
9
- id: { type: 'string', pattern: '^([\\d\\w]+)$' },
10
- },
11
- querystring: {
12
- debug: { type: 'string', pattern: '^(\\d+)$' },
13
- },
14
- };
15
-
16
- async function route(fastify, opt) {
17
- const prefix = opt.prefix || '/api';
18
- fastify.route({
19
- method: 'DELETE',
20
- url: `${prefix}/widget/:type/:objectid/:id`,
21
- schema: tableSchema,
22
- handler: widgetDel,
23
- });
24
- fastify.route({
25
- method: 'POST',
26
- path: `${prefix}/widget/:type/:objectid/:id?`,
27
- schema: tableSchema,
28
- handler: widgetSet,
29
- });
30
- fastify.route({
31
- method: 'GET',
32
- path: `${prefix}/widget/:type/:objectid`,
33
- config: {
34
- policy: ['public'],
35
- },
36
- schema: tableSchema,
37
- handler: widgetGet,
38
- });
39
- }
40
- export default route;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes