@opengis/fastify-table 1.1.51 → 1.1.52
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/.eslintrc.cjs +42 -42
- package/.gitlab-ci.yml +18 -18
- package/Changelog.md +352 -352
- package/README.md +26 -26
- package/config.js +10 -10
- package/cron/controllers/cronApi.js +22 -22
- package/cron/controllers/utils/cronList.js +1 -1
- package/cron/funcs/addCron.js +132 -132
- package/cron/index.js +12 -10
- package/cron/schema.js +8 -0
- package/crud/controllers/deleteCrud.js +36 -36
- package/crud/controllers/insert.js +71 -71
- package/crud/controllers/update.js +76 -76
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/dataDelete.js +19 -19
- package/crud/funcs/dataInsert.js +30 -30
- package/crud/funcs/dataUpdate.js +48 -48
- package/crud/funcs/getAccess.js +46 -46
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setOpt.js +16 -16
- package/crud/funcs/setToken.js +53 -53
- package/crud/funcs/utils/getFolder.js +9 -9
- package/crud/funcs/utils/logChanges.js +62 -62
- package/crud/index.js +31 -36
- package/crud/schema.js +11 -0
- package/docs/.vitepress/abbr.mjs +26 -26
- package/docs/.vitepress/config.mjs +127 -127
- package/docs/.vitepress/navigation.mjs +82 -82
- package/docs/.vitepress/theme/Layout.vue +17 -17
- package/docs/.vitepress/theme/components/NavigationLinks.vue +102 -102
- package/docs/.vitepress/theme/components/Panzoom.vue +169 -169
- package/docs/.vitepress/theme/index.mjs +15 -15
- package/docs/.vitepress/theme/style.scss +163 -163
- package/docs/abbr.json +4 -4
- package/docs/api/cron/cronApi.md +56 -56
- package/docs/api/crud/deleteCrud.md +58 -58
- package/docs/api/crud/insert.md +82 -82
- package/docs/api/crud/update.md +85 -85
- package/docs/api/index.md +47 -47
- package/docs/api/notification/testEmail.md +91 -91
- package/docs/api/table/card.md +73 -73
- package/docs/api/table/data.md +134 -134
- package/docs/api/table/export.md +60 -60
- package/docs/api/table/filter.md +104 -104
- package/docs/api/table/form.md +126 -126
- package/docs/api/table/search.md +123 -123
- package/docs/api/table/suggest.md +156 -156
- package/docs/api/table/table.md +107 -107
- package/docs/api/user/user.cls.id.md +77 -77
- package/docs/api/user/user.cls.md +49 -49
- package/docs/api/user/user.cls.post.md +62 -62
- package/docs/api/user/user.info.md +37 -37
- package/docs/api/utils/logger.file.md +60 -60
- package/docs/api/utils/next.id.md +34 -34
- package/docs/api/utils/properties.add.md +127 -127
- package/docs/api/utils/properties.get.md +73 -73
- package/docs/api/utils/status.monitor.md +36 -36
- package/docs/api/widget/widget.del.md +76 -76
- package/docs/api/widget/widget.get.md +233 -233
- package/docs/api/widget/widget.set.md +88 -88
- package/docs/db/admin.md +947 -947
- package/docs/db/crm.md +564 -564
- package/docs/db/index.md +9 -9
- package/docs/db/log.md +204 -204
- package/docs/hook/card/afterCard.md +20 -20
- package/docs/hook/card/preCard.md +25 -25
- package/docs/hook/data/afterData.md +26 -26
- package/docs/hook/data/preData.md +26 -26
- package/docs/hook/deleteCrud/afterDelete.md +21 -21
- package/docs/hook/deleteCrud/preDelete.md +26 -26
- package/docs/hook/form/afterForm.md +19 -19
- package/docs/hook/form/preForm.md +26 -26
- package/docs/hook/getTemplate/afterTemplate.md +24 -24
- package/docs/hook/getTemplate/preTemplate.md +29 -29
- package/docs/hook/index.md +45 -45
- package/docs/hook/insert/afterInsert.md +41 -41
- package/docs/hook/insert/preInsert.md +25 -25
- package/docs/hook/table/afterTable.md +20 -20
- package/docs/hook/table/preTable.md +25 -25
- package/docs/hook/update/afterUpdate.md +41 -41
- package/docs/hook/update/preUpdate.md +25 -25
- package/docs/index.md +42 -42
- package/docs/public/fastify-dark.svg +3 -3
- package/docs/public/logo-short-dark.svg +11 -11
- package/docs/public/logo-short.svg +10 -10
- package/docs/public/logo.svg +19 -19
- package/docs/readme/index.md +121 -121
- package/docs/templates/card.md +83 -83
- package/docs/templates/cls.md +29 -29
- package/docs/templates/filters.md +91 -91
- package/docs/templates/forms.md +139 -139
- package/docs/templates/index.md +28 -28
- package/docs/templates/select.md +90 -90
- package/docs/templates/table.md +162 -162
- package/docs/utils/cron/addCron.md +29 -29
- package/docs/utils/crud/dataInsert.md +51 -51
- package/docs/utils/crud/dataUpdate.md +52 -52
- package/docs/utils/crud/getOpt.md +33 -33
- package/docs/utils/crud/isFileExists.md +37 -37
- package/docs/utils/crud/setOpt.md +37 -37
- package/docs/utils/hook/addHook.md +74 -74
- package/docs/utils/hook/applyHook.md +64 -64
- package/docs/utils/index.md +47 -47
- package/docs/utils/notification/addNotification.md +28 -28
- package/docs/utils/notification/notification.md +41 -41
- package/docs/utils/pg/autoIndex.md +22 -22
- package/docs/utils/pg/getMeta.md +58 -58
- package/docs/utils/pg/getPG.md +34 -34
- package/docs/utils/pg/init.md +29 -29
- package/docs/utils/pg/pg.md +70 -70
- package/docs/utils/redis/getRedis.md +36 -36
- package/docs/utils/redis/rclient.md +74 -74
- package/docs/utils/table/getForm.md +68 -68
- package/docs/utils/table/getMeta.md +55 -55
- package/docs/utils/table/getSelect.md +38 -38
- package/docs/utils/table/getSelectMeta.md +46 -46
- package/docs/utils/table/getTable.md +77 -77
- package/helper.js +30 -30
- package/index.js +105 -105
- package/migration/exec.migrations.js +79 -79
- package/module/core/select/core.user_mentioned.sql +1 -1
- package/module/test/cls/itree.composition.json +25 -25
- package/module/test/table/test.rest_zone.table.json +265 -265
- package/notification/controllers/readNotifications.js +27 -30
- package/notification/controllers/testEmail.js +46 -50
- package/notification/controllers/userNotifications.js +61 -64
- package/notification/funcs/addNotification.js +21 -21
- package/notification/funcs/sendNotification.js +112 -112
- package/notification/index.js +3 -8
- package/notification/schema.js +10 -0
- package/package.json +41 -41
- package/pg/funcs/getMeta.js +29 -29
- package/pg/funcs/getPG.js +30 -30
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +92 -92
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/getRedis.js +23 -23
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/0.sql +78 -78
- package/server/migrations/cls.sql +39 -39
- package/server/migrations/log.sql +80 -80
- package/server/migrations/properties.sql +144 -144
- package/server/migrations/roles.sql +172 -172
- package/server/migrations/users.sql +168 -168
- package/server.js +26 -26
- package/table/controllers/data.js +157 -150
- package/table/controllers/filter.js +61 -50
- package/table/controllers/form.js +42 -42
- package/table/controllers/search.js +76 -80
- package/table/controllers/suggest.js +79 -79
- package/table/controllers/table.js +83 -83
- package/table/controllers/utils/addTemplateDir.js +8 -8
- package/table/controllers/utils/getSelect.js +19 -19
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate_old.js +28 -28
- package/table/controllers/utils/getTemplates.js +18 -18
- package/table/controllers/utils/gisIRColumn.js +72 -67
- package/table/controllers/utils/loadTemplate.js +1 -1
- package/table/controllers/utils/loadTemplatePath.js +1 -1
- package/table/controllers/utils/userTemplateDir.js +1 -1
- package/table/funcs/getFilterSQL/index.js +94 -94
- package/table/funcs/getFilterSQL/util/formatValue.js +170 -170
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/table/funcs/metaFormat/getSelectVal.js +21 -21
- package/table/funcs/metaFormat/index.js +28 -28
- package/table/index.js +37 -37
- package/table/schema.js +64 -54
- package/test/api/applyHook.test.js +95 -95
- package/test/api/crud.test.js +89 -89
- package/test/api/crud.xss.test.js +80 -80
- package/test/api/suggest.test.js +66 -66
- package/test/api/table.test.js +134 -134
- package/test/api/user.test.js +85 -85
- package/test/api/widget.test.js +117 -117
- package/test/config.example +18 -18
- package/test/funcs/pg.test.js +34 -34
- package/test/funcs/redis.test.js +19 -19
- package/test/helper/formatDate.test.js +62 -62
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +3 -3
- package/test/templates/select/storage.data.json +2 -2
- package/test/templates/select/test.storage.data.json +3 -3
- package/test/templates/select/test.suggest.ato_new.json +3 -3
- package/test/templates/select/test.suggest.ato_new.sql +25 -25
- package/test/templates/select/test.suggest.data.json +4 -4
- package/test/templates/select/test.suggest.parent.sql +1 -1
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/user/controllers/user.cls.id.js +14 -14
- package/user/controllers/user.cls.js +71 -75
- package/user/controllers/user.cls.post.js +52 -55
- package/user/controllers/user.info.js +17 -21
- package/user/index.js +7 -36
- package/user/schema.js +17 -0
- package/util/controllers/logger.file.js +91 -91
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.add.js +56 -60
- package/util/controllers/properties.get.js +16 -19
- package/util/controllers/status.monitor.js +8 -8
- package/util/controllers/utils/checkUserAccess.js +20 -17
- package/util/controllers/utils/getRootDir.js +25 -25
- package/util/index.js +19 -23
- package/util/schema.js +19 -0
- package/utils.js +106 -104
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +41 -44
- package/widget/controllers/widget.get.js +96 -102
- package/widget/controllers/widget.set.js +74 -79
- package/widget/index.js +40 -40
package/utils.js
CHANGED
|
@@ -1,104 +1,106 @@
|
|
|
1
|
-
// This file contains code that we reuse
|
|
2
|
-
// between our tests.
|
|
3
|
-
|
|
4
|
-
import { handlebars } from '@opengis/fastify-hb/utils.js';
|
|
5
|
-
import getTemplate from './table/controllers/utils/getTemplate.js';
|
|
6
|
-
import getTemplatePath from './table/controllers/utils/getTemplatePath.js';
|
|
7
|
-
import addTemplateDir from './table/controllers/utils/addTemplateDir.js';
|
|
8
|
-
import userTemplateDir from './table/controllers/utils/userTemplateDir.js';
|
|
9
|
-
import metaFormat from './table/funcs/metaFormat/index.js';
|
|
10
|
-
import autoIndex from './pg/funcs/autoIndex.js';
|
|
11
|
-
|
|
12
|
-
import getPG from './pg/funcs/getPG.js';
|
|
13
|
-
import getPGAsync from './pg/funcs/getPGAsync.js';
|
|
14
|
-
import initPG from './pg/funcs/init.js';
|
|
15
|
-
import pgClients from './pg/pgClients.js';
|
|
16
|
-
import getRedis from './redis/funcs/getRedis.js';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import
|
|
40
|
-
import
|
|
41
|
-
import
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
import
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
1
|
+
// This file contains code that we reuse
|
|
2
|
+
// between our tests.
|
|
3
|
+
|
|
4
|
+
import { handlebars } from '@opengis/fastify-hb/utils.js';
|
|
5
|
+
import getTemplate from './table/controllers/utils/getTemplate.js';
|
|
6
|
+
import getTemplatePath from './table/controllers/utils/getTemplatePath.js';
|
|
7
|
+
import addTemplateDir from './table/controllers/utils/addTemplateDir.js';
|
|
8
|
+
import userTemplateDir from './table/controllers/utils/userTemplateDir.js';
|
|
9
|
+
import metaFormat from './table/funcs/metaFormat/index.js';
|
|
10
|
+
import autoIndex from './pg/funcs/autoIndex.js';
|
|
11
|
+
|
|
12
|
+
import getPG from './pg/funcs/getPG.js';
|
|
13
|
+
import getPGAsync from './pg/funcs/getPGAsync.js';
|
|
14
|
+
import initPG from './pg/funcs/init.js';
|
|
15
|
+
import pgClients from './pg/pgClients.js';
|
|
16
|
+
import getRedis from './redis/funcs/getRedis.js';
|
|
17
|
+
import redisClients from './redis/funcs/redisClients.js';
|
|
18
|
+
|
|
19
|
+
import dataInsert from './crud/funcs/dataInsert.js';
|
|
20
|
+
import dataUpdate from './crud/funcs/dataUpdate.js';
|
|
21
|
+
import dataDelete from './crud/funcs/dataDelete.js';
|
|
22
|
+
|
|
23
|
+
import getToken from './crud/funcs/getToken.js';
|
|
24
|
+
import setToken from './crud/funcs/setToken.js';
|
|
25
|
+
import checkXSS from './crud/controllers/utils/checkXSS.js';
|
|
26
|
+
import getTableColumn from './table/controllers/utils/gisIRColumn.js';
|
|
27
|
+
import getMeta from './pg/funcs/getMeta.js';
|
|
28
|
+
import getAccess from './crud/funcs/getAccess.js';
|
|
29
|
+
import getSelectVal from './table/funcs/metaFormat/getSelectVal.js';
|
|
30
|
+
import getSelect from './table/controllers/utils/getSelect.js';
|
|
31
|
+
import getSelectMeta from './table/controllers/utils/getSelectMeta.js';
|
|
32
|
+
import applyHook from './hook/funcs/applyHook.js';
|
|
33
|
+
import addHook from './hook/funcs/addHook.js';
|
|
34
|
+
import execMigrations from './migration/exec.migrations.js';
|
|
35
|
+
import addNotification from './notification/funcs/addNotification.js';
|
|
36
|
+
import sendNotification from './notification/funcs/sendNotification.js';
|
|
37
|
+
import getFilterSQL from './table/funcs/getFilterSQL/index.js';
|
|
38
|
+
|
|
39
|
+
import addCron from './cron/funcs/addCron.js';
|
|
40
|
+
import config from './config.js';
|
|
41
|
+
import getOpt from './crud/funcs/getOpt.js';
|
|
42
|
+
import setOpt from './crud/funcs/setOpt.js';
|
|
43
|
+
|
|
44
|
+
import isFileExists from './crud/funcs/isFileExists.js';
|
|
45
|
+
import getFolder from './crud/funcs/utils/getFolder.js';
|
|
46
|
+
|
|
47
|
+
import logger from './logger/getLogger.js';
|
|
48
|
+
|
|
49
|
+
export default null;
|
|
50
|
+
export {
|
|
51
|
+
config,
|
|
52
|
+
getFolder,
|
|
53
|
+
handlebars,
|
|
54
|
+
getFilterSQL,
|
|
55
|
+
addCron,
|
|
56
|
+
execMigrations,
|
|
57
|
+
getRedis,
|
|
58
|
+
redisClients,
|
|
59
|
+
logger,
|
|
60
|
+
isFileExists,
|
|
61
|
+
|
|
62
|
+
// hook
|
|
63
|
+
addHook,
|
|
64
|
+
applyHook,
|
|
65
|
+
|
|
66
|
+
// template
|
|
67
|
+
getTemplate,
|
|
68
|
+
getTemplatePath,
|
|
69
|
+
addTemplateDir,
|
|
70
|
+
userTemplateDir,
|
|
71
|
+
|
|
72
|
+
// notification
|
|
73
|
+
addNotification,
|
|
74
|
+
sendNotification,
|
|
75
|
+
|
|
76
|
+
// security
|
|
77
|
+
checkXSS,
|
|
78
|
+
getAccess,
|
|
79
|
+
getToken,
|
|
80
|
+
getOpt,
|
|
81
|
+
setOpt,
|
|
82
|
+
setToken,
|
|
83
|
+
|
|
84
|
+
// crud
|
|
85
|
+
dataInsert,
|
|
86
|
+
dataUpdate,
|
|
87
|
+
dataDelete,
|
|
88
|
+
|
|
89
|
+
// table
|
|
90
|
+
autoIndex,
|
|
91
|
+
metaFormat,
|
|
92
|
+
getMeta,
|
|
93
|
+
getTableColumn,
|
|
94
|
+
|
|
95
|
+
// pg
|
|
96
|
+
initPG,
|
|
97
|
+
getPG,
|
|
98
|
+
getPGAsync,
|
|
99
|
+
pgClients,
|
|
100
|
+
|
|
101
|
+
// select
|
|
102
|
+
getSelectVal,
|
|
103
|
+
getSelectMeta,
|
|
104
|
+
getSelect,
|
|
105
|
+
|
|
106
|
+
};
|
|
@@ -1,76 +1,76 @@
|
|
|
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
|
+
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 +1,13 @@
|
|
|
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
|
+
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,44 +1,41 @@
|
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return { message: err.toString(), status: 500 };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
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
|
+
}
|