@opengis/fastify-table 1.0.89 → 1.0.90
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/Changelog.md +4 -0
- package/crud/controllers/deleteCrud.js +19 -19
- package/crud/controllers/insert.js +54 -54
- package/crud/controllers/update.js +59 -59
- package/crud/funcs/dataInsert.js +24 -24
- package/crud/funcs/dataUpdate.js +24 -24
- package/crud/funcs/getAccess.js +53 -53
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/setOpt.js +16 -16
- package/helper.js +28 -28
- package/index.js +97 -97
- package/notification/controllers/userNotifications.js +19 -19
- package/notification/funcs/addNotification.js +8 -8
- package/package.json +1 -1
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +83 -83
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/0.sql +78 -78
- package/server/templates/form/test.dataset.form.json +411 -411
- package/server/templates/table/test.dataset.table.json +28 -28
- package/server/templates/table/test.gis.map.table.json +44 -44
- package/table/controllers/data.js +103 -103
- package/table/controllers/suggest.js +79 -79
- package/table/controllers/table.js +49 -49
- package/table/controllers/utils/gisIRColumn.js +68 -68
- package/table/funcs/getFilterSQL/index.js +75 -75
- package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/table/funcs/metaFormat/getSelectVal.js +20 -20
- package/table/funcs/metaFormat/index.js +28 -28
- package/test/api/crud.test.js +88 -88
- package/test/api/table.test.js +89 -89
- package/util/controllers/logger.file.js +90 -0
- package/util/controllers/status.monitor.js +8 -8
- package/util/controllers/utils/checkUserAccess.js +19 -0
- package/util/controllers/utils/getRootDir.js +21 -0
- package/util/index.js +23 -21
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +44 -44
- package/widget/controllers/widget.get.js +96 -96
- package/widget/controllers/widget.set.js +70 -70
package/test/api/table.test.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import pgClients from '../../pg/pgClients.js';
|
|
4
|
-
import init from '../../pg/funcs/init.js';
|
|
5
|
-
|
|
6
|
-
import build from '../../helper.js';
|
|
7
|
-
import config from '../config.js';
|
|
8
|
-
|
|
9
|
-
test('api table', async (t) => {
|
|
10
|
-
const app = await build(t);
|
|
11
|
-
await init(pgClients.client);
|
|
12
|
-
|
|
13
|
-
const bbox = '20.276526313524393 40.6651677831094,35.27752631352439 50.66616778310941';
|
|
14
|
-
const { count = 0 } = await pgClients.client.query(`select count(*) from gis.dataset
|
|
15
|
-
where geom && 'box(${bbox})'::box2d`)
|
|
16
|
-
.then((res) => res.rows[0] || {});
|
|
17
|
-
|
|
18
|
-
await t.test('GET /data (meta bbox / cls)', async () => {
|
|
19
|
-
const res = await app.inject({
|
|
20
|
-
method: 'GET',
|
|
21
|
-
url: `${config.prefix || '/api'}/data/test.dataset.table?bbox=${bbox}`,
|
|
22
|
-
});
|
|
23
|
-
const json = res.json();
|
|
24
|
-
assert.ok(json?.rows?.length === +count, 'meta bbox - not ok');
|
|
25
|
-
assert.ok(json?.rows?.length ? json?.rows?.[0]?.dataset_id_text : true, 'meta cls - not ok');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const polyline = 'wfvkH_jsvCoKvj@oKfiB?fw@?nd@?nK?nK~WgEfE?wQfw@gEfE?vQwQvj@wQvcAoKvQoKnKgEnd@_cBgw@wj@fEwj@nKg^vQg^oK?vQgEnKgpAvj@?vcAfEf^fEf^?vj@vQvj@vQ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vQg^fEoKnKoKvQnK~WfEnKvQ~Wod@f^wj@~WoKnKg^~W?vQgE~WoKnKoK~WoKfEwQvQwQfEgEnKwQnKwQvQwQnKoKnKgEnKgEnKgEvQnKnK?fE?fE?~WwQnKgEnKgEfE?fE?nK?fE?fE?vQgEfE?nKfEfE?fE?vQ?~W?~WgEfEgEnKgEnKwQfEnKnKfE?wj@?o}@g^o}@_Xod@?gEf^_X?o}@?wQ~W?~WgE~WgEfE?f^gEf^oK~Wg^nKgE?oK~WwQ?od@nK_XfEwQnKoKfEgEfE~W?f^f^fEfEfEnKfEnK?gEf^vQfEnK?~WnKvQnK?vQf^nKfEfEgE~WnKfEnK?fEgEfE?nK?fEfEfEgEnK?nKgEnK?nKfEf^?vQgEvQ?nd@gEnKo}@vQgE~WgEf^gE'; // UA26040270000047749
|
|
29
|
-
|
|
30
|
-
const { count1 } = await pgClients.client.query('select count(*) as count1 from gis.dataset where ST_Contains(ST_MakePolygon(ST_LineFromEncodedPolyline($1)),geom)', [polyline])
|
|
31
|
-
.then((res) => res.rows[0] || {});
|
|
32
|
-
await t.test('GET /data (meta polyline)', async () => {
|
|
33
|
-
const res = await app.inject({
|
|
34
|
-
method: 'GET',
|
|
35
|
-
url: `${config.prefix || '/api'}/data/test.dataset.table?polyline=${polyline}`,
|
|
36
|
-
});
|
|
37
|
-
const json = res.json();
|
|
38
|
-
assert.ok(json?.rows?.length === +count1, 'meta bbox (polyline) - not ok');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
/* await t.test('GET /suggest', async () => {
|
|
42
|
-
const res = await app.inject({
|
|
43
|
-
method: 'GET',
|
|
44
|
-
url: '/api/suggest/test.storage.data',
|
|
45
|
-
});
|
|
46
|
-
// console.log(res?.body);
|
|
47
|
-
const rep = JSON.parse(res?.body);
|
|
48
|
-
// console.log(rep.total);
|
|
49
|
-
assert.ok(rep.total);
|
|
50
|
-
}); */
|
|
51
|
-
/* await t.test('GET /data', async () => {
|
|
52
|
-
const res = await app.inject({
|
|
53
|
-
method: 'GET',
|
|
54
|
-
url: '/api/data/test.dataset.table',
|
|
55
|
-
});
|
|
56
|
-
// console.log(res);
|
|
57
|
-
const rep = JSON.parse(res?.body);
|
|
58
|
-
// console.log(rep.total);
|
|
59
|
-
assert.ok(rep.total);
|
|
60
|
-
}); */
|
|
61
|
-
/* await t.test('GET /search', async () => {
|
|
62
|
-
const res = await app.inject({
|
|
63
|
-
method: 'GET',
|
|
64
|
-
url: '/api/search?table=test.dataset.table&key=0',
|
|
65
|
-
});
|
|
66
|
-
const rep = JSON.parse(res?.body);
|
|
67
|
-
assert.ok(rep.total);
|
|
68
|
-
}); */
|
|
69
|
-
await t.test('GET /form', async () => {
|
|
70
|
-
const res = await app.inject({
|
|
71
|
-
method: 'GET',
|
|
72
|
-
url: '/api/form/test.dataset.form',
|
|
73
|
-
});
|
|
74
|
-
// console.log(res);
|
|
75
|
-
const rep = JSON.parse(res?.body);
|
|
76
|
-
// console.log(rep.total);
|
|
77
|
-
assert.ok(rep);
|
|
78
|
-
});
|
|
79
|
-
await t.test('GET /filter', async () => {
|
|
80
|
-
const res = await app.inject({
|
|
81
|
-
method: 'GET',
|
|
82
|
-
url: '/api/filter/test.dataset.table',
|
|
83
|
-
});
|
|
84
|
-
// console.log(res);
|
|
85
|
-
const rep = JSON.parse(res?.body);
|
|
86
|
-
// console.log(rep.total);
|
|
87
|
-
assert.ok(rep);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import pgClients from '../../pg/pgClients.js';
|
|
4
|
+
import init from '../../pg/funcs/init.js';
|
|
5
|
+
|
|
6
|
+
import build from '../../helper.js';
|
|
7
|
+
import config from '../config.js';
|
|
8
|
+
|
|
9
|
+
test('api table', async (t) => {
|
|
10
|
+
const app = await build(t);
|
|
11
|
+
await init(pgClients.client);
|
|
12
|
+
|
|
13
|
+
const bbox = '20.276526313524393 40.6651677831094,35.27752631352439 50.66616778310941';
|
|
14
|
+
const { count = 0 } = await pgClients.client.query(`select count(*) from gis.dataset
|
|
15
|
+
where geom && 'box(${bbox})'::box2d`)
|
|
16
|
+
.then((res) => res.rows[0] || {});
|
|
17
|
+
|
|
18
|
+
await t.test('GET /data (meta bbox / cls)', async () => {
|
|
19
|
+
const res = await app.inject({
|
|
20
|
+
method: 'GET',
|
|
21
|
+
url: `${config.prefix || '/api'}/data/test.dataset.table?bbox=${bbox}`,
|
|
22
|
+
});
|
|
23
|
+
const json = res.json();
|
|
24
|
+
assert.ok(json?.rows?.length === +count, 'meta bbox - not ok');
|
|
25
|
+
assert.ok(json?.rows?.length ? json?.rows?.[0]?.dataset_id_text : true, 'meta cls - not ok');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const polyline = 'wfvkH_jsvCoKvj@oKfiB?fw@?nd@?nK?nK~WgEfE?wQfw@gEfE?vQwQvj@wQvcAoKvQoKnKgEnd@_cBgw@wj@fEwj@nKg^vQg^oK?vQgEnKgpAvj@?vcAfEf^fEf^?vj@vQvj@vQgE~Wvj@?~p@gE~iAfEnK?~iA_XnvA?nd@fEf^~p@~bBvQ?nd@wQ?vQfEf^fEnK?vQ?vj@oKfEoKfEvQnd@nKvj@?vQfEvQgEf^gEf^?vQfEvQfEvQfE~W?fE?fE?~W?f^?nd@?nK?nKfEfEg^oKwj@nK_X~W~p@~WvQnKoKn}@wQvj@oK~Wg^vcAgEnK?~Wfw@vgD~p@oKfpAvQnd@nKoKvQoKvQ?fE?fEnKvj@wQvQ?fEod@fw@~Wn}@fEn}@_Xv|A_jA~fEwQwQ_XoKwQoKoKoKoKoKg^gE_XgEoKg^gEgEgE?gEfEgEfEgEf^_XoKwQ?gEgEoK?wQ?gE~WoKoKoKwQfEgEnK_X?gEgE?oKfEoKoKgE_XgEgEwQfEoKod@_Xgw@gEoKgE_Xg^wQoKg^_XnvAgE?gEvQgE?od@fpA?vQ?f^oKvcAwj@oKg^?wQn}@gEf^oK?w|AnKgE??n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contains(ST_MakePolygon(ST_LineFromEncodedPolyline($1)),geom)', [polyline])
|
|
31
|
+
.then((res) => res.rows[0] || {});
|
|
32
|
+
await t.test('GET /data (meta polyline)', async () => {
|
|
33
|
+
const res = await app.inject({
|
|
34
|
+
method: 'GET',
|
|
35
|
+
url: `${config.prefix || '/api'}/data/test.dataset.table?polyline=${polyline}`,
|
|
36
|
+
});
|
|
37
|
+
const json = res.json();
|
|
38
|
+
assert.ok(json?.rows?.length === +count1, 'meta bbox (polyline) - not ok');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/* await t.test('GET /suggest', async () => {
|
|
42
|
+
const res = await app.inject({
|
|
43
|
+
method: 'GET',
|
|
44
|
+
url: '/api/suggest/test.storage.data',
|
|
45
|
+
});
|
|
46
|
+
// console.log(res?.body);
|
|
47
|
+
const rep = JSON.parse(res?.body);
|
|
48
|
+
// console.log(rep.total);
|
|
49
|
+
assert.ok(rep.total);
|
|
50
|
+
}); */
|
|
51
|
+
/* await t.test('GET /data', async () => {
|
|
52
|
+
const res = await app.inject({
|
|
53
|
+
method: 'GET',
|
|
54
|
+
url: '/api/data/test.dataset.table',
|
|
55
|
+
});
|
|
56
|
+
// console.log(res);
|
|
57
|
+
const rep = JSON.parse(res?.body);
|
|
58
|
+
// console.log(rep.total);
|
|
59
|
+
assert.ok(rep.total);
|
|
60
|
+
}); */
|
|
61
|
+
/* await t.test('GET /search', async () => {
|
|
62
|
+
const res = await app.inject({
|
|
63
|
+
method: 'GET',
|
|
64
|
+
url: '/api/search?table=test.dataset.table&key=0',
|
|
65
|
+
});
|
|
66
|
+
const rep = JSON.parse(res?.body);
|
|
67
|
+
assert.ok(rep.total);
|
|
68
|
+
}); */
|
|
69
|
+
await t.test('GET /form', async () => {
|
|
70
|
+
const res = await app.inject({
|
|
71
|
+
method: 'GET',
|
|
72
|
+
url: '/api/form/test.dataset.form',
|
|
73
|
+
});
|
|
74
|
+
// console.log(res);
|
|
75
|
+
const rep = JSON.parse(res?.body);
|
|
76
|
+
// console.log(rep.total);
|
|
77
|
+
assert.ok(rep);
|
|
78
|
+
});
|
|
79
|
+
await t.test('GET /filter', async () => {
|
|
80
|
+
const res = await app.inject({
|
|
81
|
+
method: 'GET',
|
|
82
|
+
url: '/api/filter/test.dataset.table',
|
|
83
|
+
});
|
|
84
|
+
// console.log(res);
|
|
85
|
+
const rep = JSON.parse(res?.body);
|
|
86
|
+
// console.log(rep.total);
|
|
87
|
+
assert.ok(rep);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { lstat, readdir } from 'fs/promises';
|
|
3
|
+
import { createReadStream, existsSync } from 'fs';
|
|
4
|
+
import readline from 'readline';
|
|
5
|
+
|
|
6
|
+
import checkUserAccess from './utils/checkUserAccess.js';
|
|
7
|
+
import getRootDir from './utils/getRootDir.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @method GET
|
|
12
|
+
* @summary API для перегляду логів
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export default async function loggerFile({
|
|
17
|
+
pg, params = {}, user = {}, query = {}, originalUrl, funcs = {},
|
|
18
|
+
}, reply) {
|
|
19
|
+
const limit = 200000;
|
|
20
|
+
const access = pg ? await checkUserAccess({ user, pg }) : {};
|
|
21
|
+
|
|
22
|
+
const { config = {} } = funcs;
|
|
23
|
+
if (access?.status === 403 && !config?.local) return access;
|
|
24
|
+
|
|
25
|
+
// absolute / relative path
|
|
26
|
+
const rootDir = getRootDir(config);
|
|
27
|
+
const filepath = path.join(rootDir, params['*'] || '');
|
|
28
|
+
|
|
29
|
+
if (!existsSync(filepath)) {
|
|
30
|
+
return { error: 'file not exists', status: 404 };
|
|
31
|
+
}
|
|
32
|
+
const stat = await lstat(filepath);
|
|
33
|
+
const isFile = stat.isFile();
|
|
34
|
+
|
|
35
|
+
if (query.download && isFile) {
|
|
36
|
+
return reply.download(filepath);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (query.full && isFile) {
|
|
40
|
+
if (stat.size > 20 * 1000 * 1000) {
|
|
41
|
+
return { message: 'file size > 20MB' };
|
|
42
|
+
}
|
|
43
|
+
const buffer = await readFile(filepath, { buffer: true });
|
|
44
|
+
return buffer;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isFile) {
|
|
48
|
+
const ext = path.extname(filepath);
|
|
49
|
+
|
|
50
|
+
const lines = await new Promise((resolve) => {
|
|
51
|
+
const rl = readline.createInterface({
|
|
52
|
+
input: createReadStream(filepath, { start: stat.size > limit ? stat.size - limit : 0 }),
|
|
53
|
+
});
|
|
54
|
+
const lines1 = [];
|
|
55
|
+
rl.on('close', () => resolve(lines1));
|
|
56
|
+
rl.on('line', (line) => lines1.push(line));
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (ext === '.html') {
|
|
60
|
+
const buffer = await readFile(filepath, { buffer: true });
|
|
61
|
+
reply.headers({ 'Content-type': 'text/html; charset=UTF-8' });
|
|
62
|
+
return buffer;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
reply.headers({ 'Content-type': 'text/plain' });
|
|
66
|
+
return stat.size > limit && lines.length > 1
|
|
67
|
+
? lines.reverse().slice(0, -1).join('\n')
|
|
68
|
+
: lines.reverse().join('\n');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// dir
|
|
72
|
+
const files = await readdir(filepath);
|
|
73
|
+
|
|
74
|
+
if (query.dir) {
|
|
75
|
+
return files.filter((el) => !['backup', 'marker_icon', 'error', 'migration'].includes(el));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const lstatsArr = await Promise.all(files.map(async (file) => [file, await lstat(path.join(filepath, file))]));
|
|
79
|
+
const lstats = Object.fromEntries(lstatsArr);
|
|
80
|
+
|
|
81
|
+
const message = (params['*'] ? '<a href="/logger-file/">...</a><br>' : '')
|
|
82
|
+
+ files.map((file) => `<a href="${originalUrl}/${file}">${file}</a> (${lstats[file].size} bytes)`).join('</br>');
|
|
83
|
+
|
|
84
|
+
reply.headers({
|
|
85
|
+
'Content-Type': 'text/html; charset=UTF-8',
|
|
86
|
+
'Content-Security-Policy': "default-src 'none'",
|
|
87
|
+
'X-Content-Type-Options': 'nosniff',
|
|
88
|
+
});
|
|
89
|
+
return message;
|
|
90
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
2
|
-
|
|
3
|
-
export default async function statusMonitor() {
|
|
4
|
-
const memoryUsage = process.memoryUsage();
|
|
5
|
-
const message = Object.keys(memoryUsage)
|
|
6
|
-
.reduce((acc, curr) => Object.assign(acc, { [curr]: formatMemoryUsage(memoryUsage[curr]) }), {});
|
|
7
|
-
return { message, status: 200 };
|
|
8
|
-
}
|
|
1
|
+
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
2
|
+
|
|
3
|
+
export default async function statusMonitor() {
|
|
4
|
+
const memoryUsage = process.memoryUsage();
|
|
5
|
+
const message = Object.keys(memoryUsage)
|
|
6
|
+
.reduce((acc, curr) => Object.assign(acc, { [curr]: formatMemoryUsage(memoryUsage[curr]) }), {});
|
|
7
|
+
return { message, status: 200 };
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @summary check user access to logger interface - per admin user type or user group
|
|
4
|
+
* @returns {Object} message, status
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export default async function checkUserAccess({
|
|
8
|
+
user = {}, pg,
|
|
9
|
+
}) {
|
|
10
|
+
const { count = '0' } = pg.pk?.['admin.access']
|
|
11
|
+
? await pg.query(`select count(*) from admin.access
|
|
12
|
+
where user_uid=$1 and route_id='logger'`, [user.uid]).then((res) => res.rows[0] || {})
|
|
13
|
+
: {};
|
|
14
|
+
|
|
15
|
+
if (!['admin', 'superadmin']?.includes(user.user_type) && count === '0') {
|
|
16
|
+
return { message: 'access restricted', status: 403 };
|
|
17
|
+
}
|
|
18
|
+
return { message: 'access granted', status: 200 };
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
|
|
4
|
+
export default function getRootDir(config) {
|
|
5
|
+
// absolute / relative path
|
|
6
|
+
if (config.log?.dir) {
|
|
7
|
+
return config.log.dir.startsWith('/') || config.log.dir.includes(':')
|
|
8
|
+
? config.log.dir
|
|
9
|
+
: path.join(process.cwd(), config.log.dir);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// windows debug support
|
|
13
|
+
const customLogDir = process.cwd().includes(':') ? 'c:/data/local' : '/data/local';
|
|
14
|
+
// docker default path
|
|
15
|
+
if (existsSync(customLogDir)) {
|
|
16
|
+
return path.join(customLogDir, config.folder || '', 'log');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// non-docker default path
|
|
20
|
+
return path.join(config.root || '/data/local', config.folder || '', 'log');
|
|
21
|
+
}
|
package/util/index.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
-
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
-
import nextId from './controllers/next.id.js';
|
|
4
|
-
import statusMonitor from './controllers/status.monitor.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
fastify.get(`${prefix}/
|
|
17
|
-
fastify.get(`${prefix}/
|
|
18
|
-
fastify.
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
+
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
+
import nextId from './controllers/next.id.js';
|
|
4
|
+
import statusMonitor from './controllers/status.monitor.js';
|
|
5
|
+
import loggerFile from './controllers/logger.file.js';
|
|
6
|
+
|
|
7
|
+
const propertiesSchema = {
|
|
8
|
+
params: {
|
|
9
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
async function plugin(fastify, config = {}) {
|
|
14
|
+
const prefix = config.prefix || '/api';
|
|
15
|
+
|
|
16
|
+
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
17
|
+
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
18
|
+
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
19
|
+
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
20
|
+
fastify.get('/logger-file/*', { config: { policy: ['log'] } }, loggerFile);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default plugin;
|
|
@@ -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 existColumns = 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 existColumns = 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,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
|
-
try {
|
|
38
|
-
await pg.query(sql, [objectid, user.uid, id]);
|
|
39
|
-
return { data: { id }, user: { uid: user.uid, name: user.user_name } };
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
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
|
+
try {
|
|
38
|
+
await pg.query(sql, [objectid, user.uid, id]);
|
|
39
|
+
return { data: { id }, user: { uid: user.uid, name: user.user_name } };
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return { message: err.toString(), status: 500 };
|
|
43
|
+
}
|
|
44
|
+
}
|