@opengis/fastify-table 1.0.26 → 1.0.28
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 +8 -0
- package/crud/controllers/insert.js +29 -29
- package/crud/controllers/update.js +31 -31
- package/crud/funcs/dataInsert.js +1 -1
- package/crud/funcs/dataUpdate.js +7 -3
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/setOpt.js +16 -16
- package/crud/index.js +29 -29
- package/dblist/controllers/createItem.js +32 -17
- package/dblist/controllers/deleteItem.js +14 -12
- package/dblist/controllers/readItems.js +10 -8
- package/dblist/controllers/setItem.js +21 -0
- package/dblist/controllers/updateItem.js +25 -22
- package/dblist/controllers/utils/checkItem.js +24 -9
- package/dblist/controllers/utils/formatData.js +7 -0
- package/dblist/index.js +49 -40
- package/helper.js +28 -28
- package/index.js +41 -41
- package/notification/controllers/userNotifications.js +19 -19
- package/notification/funcs/addNotification.js +8 -8
- package/notification/index.js +19 -19
- package/package.json +1 -1
- package/pg/funcs/getPG.js +1 -1
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +74 -74
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/getRedis.js +1 -1
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/crm.sql +57 -57
- package/server/migrations/log.sql +41 -41
- package/server/migrations/notifications.sql +14 -14
- package/server/templates/form/test.dataset.form.json +411 -411
- package/server/templates/select/test.storage.data.json +2 -2
- package/server/templates/table/test.dataset.table.json +24 -24
- package/table/controllers/data.js +57 -57
- package/table/controllers/filter.js +32 -32
- package/table/controllers/form.js +10 -10
- package/table/controllers/suggest.js +60 -60
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate.js +28 -28
- 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/metaFormat/getSelectVal.js +20 -20
- package/table/funcs/metaFormat/index.js +26 -26
- package/table/index.js +42 -42
- package/test/api/crud.test.js +56 -56
- package/test/api/crud.xss.test.js +71 -71
- package/test/api/dblist.test.js +47 -47
- package/test/api/notification.test.js +37 -37
- package/test/api/table.test.js +57 -57
- package/test/api/widget.test.js +39 -39
- package/test/funcs/notification.test.js +31 -31
- package/test/widget.test.js +39 -39
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +40 -40
- package/widget/controllers/widget.get.js +74 -74
- package/widget/controllers/widget.set.js +45 -45
- package/widget/index.js +29 -29
package/test/api/table.test.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../../helper.js';
|
|
5
|
-
|
|
6
|
-
test('api table', async (t) => {
|
|
7
|
-
const app = await build(t);
|
|
8
|
-
// assert.ok(1);
|
|
9
|
-
await t.test('GET /suggest', async () => {
|
|
10
|
-
const res = await app.inject({
|
|
11
|
-
method: 'GET',
|
|
12
|
-
url: '/api/suggest/test.storage.data',
|
|
13
|
-
});
|
|
14
|
-
// console.log(res?.body);
|
|
15
|
-
const rep = JSON.parse(res?.body);
|
|
16
|
-
// console.log(rep.total);
|
|
17
|
-
assert.ok(rep.total);
|
|
18
|
-
});
|
|
19
|
-
await t.test('GET /data', async () => {
|
|
20
|
-
const res = await app.inject({
|
|
21
|
-
method: 'GET',
|
|
22
|
-
url: '/api/data/test.dataset.table',
|
|
23
|
-
});
|
|
24
|
-
// console.log(res);
|
|
25
|
-
const rep = JSON.parse(res?.body);
|
|
26
|
-
// console.log(rep.total);
|
|
27
|
-
assert.ok(rep.total);
|
|
28
|
-
});
|
|
29
|
-
await t.test('GET /search', async () => {
|
|
30
|
-
const res = await app.inject({
|
|
31
|
-
method: 'GET',
|
|
32
|
-
url: '/api/search?table=test.dataset.table&key=0',
|
|
33
|
-
});
|
|
34
|
-
const rep = JSON.parse(res?.body);
|
|
35
|
-
assert.ok(rep.total);
|
|
36
|
-
});
|
|
37
|
-
await t.test('GET /form', async () => {
|
|
38
|
-
const res = await app.inject({
|
|
39
|
-
method: 'GET',
|
|
40
|
-
url: '/api/form/test.dataset.form',
|
|
41
|
-
});
|
|
42
|
-
// console.log(res);
|
|
43
|
-
const rep = JSON.parse(res?.body);
|
|
44
|
-
// console.log(rep.total);
|
|
45
|
-
assert.ok(rep);
|
|
46
|
-
});
|
|
47
|
-
await t.test('GET /filter', async () => {
|
|
48
|
-
const res = await app.inject({
|
|
49
|
-
method: 'GET',
|
|
50
|
-
url: '/api/filter/test.dataset.table',
|
|
51
|
-
});
|
|
52
|
-
// console.log(res);
|
|
53
|
-
const rep = JSON.parse(res?.body);
|
|
54
|
-
// console.log(rep.total);
|
|
55
|
-
assert.ok(rep);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../../helper.js';
|
|
5
|
+
|
|
6
|
+
test('api table', async (t) => {
|
|
7
|
+
const app = await build(t);
|
|
8
|
+
// assert.ok(1);
|
|
9
|
+
await t.test('GET /suggest', async () => {
|
|
10
|
+
const res = await app.inject({
|
|
11
|
+
method: 'GET',
|
|
12
|
+
url: '/api/suggest/test.storage.data',
|
|
13
|
+
});
|
|
14
|
+
// console.log(res?.body);
|
|
15
|
+
const rep = JSON.parse(res?.body);
|
|
16
|
+
// console.log(rep.total);
|
|
17
|
+
assert.ok(rep.total);
|
|
18
|
+
});
|
|
19
|
+
await t.test('GET /data', async () => {
|
|
20
|
+
const res = await app.inject({
|
|
21
|
+
method: 'GET',
|
|
22
|
+
url: '/api/data/test.dataset.table',
|
|
23
|
+
});
|
|
24
|
+
// console.log(res);
|
|
25
|
+
const rep = JSON.parse(res?.body);
|
|
26
|
+
// console.log(rep.total);
|
|
27
|
+
assert.ok(rep.total);
|
|
28
|
+
});
|
|
29
|
+
await t.test('GET /search', async () => {
|
|
30
|
+
const res = await app.inject({
|
|
31
|
+
method: 'GET',
|
|
32
|
+
url: '/api/search?table=test.dataset.table&key=0',
|
|
33
|
+
});
|
|
34
|
+
const rep = JSON.parse(res?.body);
|
|
35
|
+
assert.ok(rep.total);
|
|
36
|
+
});
|
|
37
|
+
await t.test('GET /form', async () => {
|
|
38
|
+
const res = await app.inject({
|
|
39
|
+
method: 'GET',
|
|
40
|
+
url: '/api/form/test.dataset.form',
|
|
41
|
+
});
|
|
42
|
+
// console.log(res);
|
|
43
|
+
const rep = JSON.parse(res?.body);
|
|
44
|
+
// console.log(rep.total);
|
|
45
|
+
assert.ok(rep);
|
|
46
|
+
});
|
|
47
|
+
await t.test('GET /filter', async () => {
|
|
48
|
+
const res = await app.inject({
|
|
49
|
+
method: 'GET',
|
|
50
|
+
url: '/api/filter/test.dataset.table',
|
|
51
|
+
});
|
|
52
|
+
// console.log(res);
|
|
53
|
+
const rep = JSON.parse(res?.body);
|
|
54
|
+
// console.log(rep.total);
|
|
55
|
+
assert.ok(rep);
|
|
56
|
+
});
|
|
57
|
+
});
|
package/test/api/widget.test.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../../helper.js';
|
|
5
|
-
import config from '../config.js';
|
|
6
|
-
|
|
7
|
-
const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
|
|
8
|
-
|
|
9
|
-
import widgetGet from '../../widget/controllers/widget.get.js';
|
|
10
|
-
import widgetSet from '../../widget/controllers/widget.set.js';
|
|
11
|
-
import widgetDel from '../../widget/controllers/widget.del.js';
|
|
12
|
-
|
|
13
|
-
import pgClients from '../../pg/pgClients.js';
|
|
14
|
-
|
|
15
|
-
test('widget api', async (t) => {
|
|
16
|
-
await build(t);
|
|
17
|
-
const pg = pgClients.client;
|
|
18
|
-
await t.test('POST /widget/:type/:objectid', async () => {
|
|
19
|
-
const body = {};
|
|
20
|
-
const rep = await widgetSet({
|
|
21
|
-
pg, params: { type: 'comment', objectid: '1' }, session, body,
|
|
22
|
-
});
|
|
23
|
-
assert.ok(rep.data);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
let resp;
|
|
27
|
-
await t.test('GET /widget/:type/:objectid', async () => {
|
|
28
|
-
resp = await widgetGet({
|
|
29
|
-
pg, session, params: { type: 'comment', objectid: '1' },
|
|
30
|
-
});
|
|
31
|
-
assert.ok(resp.rows.length > 0, 'widget data get fail');
|
|
32
|
-
});
|
|
33
|
-
await t.test('DELETE /widget/:type/:objectid', async () => {
|
|
34
|
-
resp = await widgetDel({
|
|
35
|
-
pg, session, params: { type: 'comment', objectid: '1', id: resp.rows?.find((row) => row)?.comment_id },
|
|
36
|
-
});
|
|
37
|
-
assert.ok(resp.data.rowCount === 1, 'widget data delete fail');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../../helper.js';
|
|
5
|
+
import config from '../config.js';
|
|
6
|
+
|
|
7
|
+
const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
|
|
8
|
+
|
|
9
|
+
import widgetGet from '../../widget/controllers/widget.get.js';
|
|
10
|
+
import widgetSet from '../../widget/controllers/widget.set.js';
|
|
11
|
+
import widgetDel from '../../widget/controllers/widget.del.js';
|
|
12
|
+
|
|
13
|
+
import pgClients from '../../pg/pgClients.js';
|
|
14
|
+
|
|
15
|
+
test('widget api', async (t) => {
|
|
16
|
+
await build(t);
|
|
17
|
+
const pg = pgClients.client;
|
|
18
|
+
await t.test('POST /widget/:type/:objectid', async () => {
|
|
19
|
+
const body = {};
|
|
20
|
+
const rep = await widgetSet({
|
|
21
|
+
pg, params: { type: 'comment', objectid: '1' }, session, body,
|
|
22
|
+
});
|
|
23
|
+
assert.ok(rep.data);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
let resp;
|
|
27
|
+
await t.test('GET /widget/:type/:objectid', async () => {
|
|
28
|
+
resp = await widgetGet({
|
|
29
|
+
pg, session, params: { type: 'comment', objectid: '1' },
|
|
30
|
+
});
|
|
31
|
+
assert.ok(resp.rows.length > 0, 'widget data get fail');
|
|
32
|
+
});
|
|
33
|
+
await t.test('DELETE /widget/:type/:objectid', async () => {
|
|
34
|
+
resp = await widgetDel({
|
|
35
|
+
pg, session, params: { type: 'comment', objectid: '1', id: resp.rows?.find((row) => row)?.comment_id },
|
|
36
|
+
});
|
|
37
|
+
assert.ok(resp.data.rowCount === 1, 'widget data delete fail');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../../helper.js';
|
|
5
|
-
import config from '../config.js';
|
|
6
|
-
|
|
7
|
-
import addNotification from '../../notification/funcs/addNotification.js';
|
|
8
|
-
|
|
9
|
-
import pgClients from '../../pg/pgClients.js';
|
|
10
|
-
|
|
11
|
-
test('notification funcs', async (t) => {
|
|
12
|
-
await build(t);
|
|
13
|
-
const pg = pgClients.client;
|
|
14
|
-
let resp;
|
|
15
|
-
await t.test('addNotification', async () => {
|
|
16
|
-
resp = await addNotification({
|
|
17
|
-
pg,
|
|
18
|
-
|
|
19
|
-
title: 'test title',
|
|
20
|
-
body: 'test body',
|
|
21
|
-
link: 'http://link',
|
|
22
|
-
notificationType: 'mention',
|
|
23
|
-
uid: config.testUser?.uid || '1',
|
|
24
|
-
});
|
|
25
|
-
assert.ok(resp.id);
|
|
26
|
-
});
|
|
27
|
-
await t.test('clean up after test, before pool is closed', async () => {
|
|
28
|
-
await pg.query('delete from crm.notification where notification_id=$1', [resp.id]);
|
|
29
|
-
console.log(resp.id, 'deleted');
|
|
30
|
-
});
|
|
31
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../../helper.js';
|
|
5
|
+
import config from '../config.js';
|
|
6
|
+
|
|
7
|
+
import addNotification from '../../notification/funcs/addNotification.js';
|
|
8
|
+
|
|
9
|
+
import pgClients from '../../pg/pgClients.js';
|
|
10
|
+
|
|
11
|
+
test('notification funcs', async (t) => {
|
|
12
|
+
await build(t);
|
|
13
|
+
const pg = pgClients.client;
|
|
14
|
+
let resp;
|
|
15
|
+
await t.test('addNotification', async () => {
|
|
16
|
+
resp = await addNotification({
|
|
17
|
+
pg,
|
|
18
|
+
|
|
19
|
+
title: 'test title',
|
|
20
|
+
body: 'test body',
|
|
21
|
+
link: 'http://link',
|
|
22
|
+
notificationType: 'mention',
|
|
23
|
+
uid: config.testUser?.uid || '1',
|
|
24
|
+
});
|
|
25
|
+
assert.ok(resp.id);
|
|
26
|
+
});
|
|
27
|
+
await t.test('clean up after test, before pool is closed', async () => {
|
|
28
|
+
await pg.query('delete from crm.notification where notification_id=$1', [resp.id]);
|
|
29
|
+
console.log(resp.id, 'deleted');
|
|
30
|
+
});
|
|
31
|
+
});
|
package/test/widget.test.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../helper.js';
|
|
5
|
-
import config from '../config.js';
|
|
6
|
-
|
|
7
|
-
const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
|
|
8
|
-
|
|
9
|
-
import widgetGet from '../widget/controllers/widget.get.js';
|
|
10
|
-
import widgetSet from '../widget/controllers/widget.set.js';
|
|
11
|
-
import widgetDel from '../widget/controllers/widget.del.js';
|
|
12
|
-
|
|
13
|
-
import pgClients from '../pg/pgClients.js';
|
|
14
|
-
|
|
15
|
-
test('api && funcs notification', async (t) => {
|
|
16
|
-
const app = await build(t);
|
|
17
|
-
const pg = pgClients.client;
|
|
18
|
-
await t.test('POST /widget/:type/:objectid', async () => {
|
|
19
|
-
const body = {};
|
|
20
|
-
const rep = await widgetSet({
|
|
21
|
-
pg, params: { type: 'comment', objectid: '1' }, session, body,
|
|
22
|
-
});
|
|
23
|
-
assert.ok(rep.data);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
let resp;
|
|
27
|
-
await t.test('GET /widget/:type/:objectid', async () => {
|
|
28
|
-
resp = await widgetGet({
|
|
29
|
-
pg, session, params: { type: 'comment', objectid: '1' },
|
|
30
|
-
});
|
|
31
|
-
assert.ok(resp.rows.length > 0, 'widget data get fail');
|
|
32
|
-
});
|
|
33
|
-
await t.test('DELETE /widget/:type/:objectid', async () => {
|
|
34
|
-
resp = await widgetDel({
|
|
35
|
-
pg, session, params: { type: 'comment', objectid: '1', id: resp.rows?.find((row) => row)?.comment_id },
|
|
36
|
-
});
|
|
37
|
-
assert.ok(resp.data.rowCount === 1, 'widget data delete fail');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../helper.js';
|
|
5
|
+
import config from '../config.js';
|
|
6
|
+
|
|
7
|
+
const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
|
|
8
|
+
|
|
9
|
+
import widgetGet from '../widget/controllers/widget.get.js';
|
|
10
|
+
import widgetSet from '../widget/controllers/widget.set.js';
|
|
11
|
+
import widgetDel from '../widget/controllers/widget.del.js';
|
|
12
|
+
|
|
13
|
+
import pgClients from '../pg/pgClients.js';
|
|
14
|
+
|
|
15
|
+
test('api && funcs notification', async (t) => {
|
|
16
|
+
const app = await build(t);
|
|
17
|
+
const pg = pgClients.client;
|
|
18
|
+
await t.test('POST /widget/:type/:objectid', async () => {
|
|
19
|
+
const body = {};
|
|
20
|
+
const rep = await widgetSet({
|
|
21
|
+
pg, params: { type: 'comment', objectid: '1' }, session, body,
|
|
22
|
+
});
|
|
23
|
+
assert.ok(rep.data);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
let resp;
|
|
27
|
+
await t.test('GET /widget/:type/:objectid', async () => {
|
|
28
|
+
resp = await widgetGet({
|
|
29
|
+
pg, session, params: { type: 'comment', objectid: '1' },
|
|
30
|
+
});
|
|
31
|
+
assert.ok(resp.rows.length > 0, 'widget data get fail');
|
|
32
|
+
});
|
|
33
|
+
await t.test('DELETE /widget/:type/:objectid', async () => {
|
|
34
|
+
resp = await widgetDel({
|
|
35
|
+
pg, session, params: { type: 'comment', objectid: '1', id: resp.rows?.find((row) => row)?.comment_id },
|
|
36
|
+
});
|
|
37
|
+
assert.ok(resp.data.rowCount === 1, 'widget data delete fail');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -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,40 +1,40 @@
|
|
|
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
|
-
if (!['comment', 'checklist', 'link', 'time'].includes(type)) return { error: 'type not valid required', status: 401 };
|
|
27
|
-
if (!objectid) return { error: 'id required', status: 400 };
|
|
28
|
-
|
|
29
|
-
const sql = {
|
|
30
|
-
comment: 'delete from crm.comment where object_id=$1 and uid=$2 and comment_id=$3',
|
|
31
|
-
checklist: 'delete from crm.checklist where object_id=$1 and uid=$2 and checklist_id=$3 ',
|
|
32
|
-
};
|
|
33
|
-
try {
|
|
34
|
-
const { rows, rowCount } = await pg.query(sql[type], [objectid, user.uid, id]);
|
|
35
|
-
return { data: { rows, rowCount }, user: { uid: user.uid, name: user.user_name } };
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
return { message: err.toString(), status: 500 };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
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
|
+
if (!['comment', 'checklist', 'link', 'time'].includes(type)) return { error: 'type not valid required', status: 401 };
|
|
27
|
+
if (!objectid) return { error: 'id required', status: 400 };
|
|
28
|
+
|
|
29
|
+
const sql = {
|
|
30
|
+
comment: 'delete from crm.comment where object_id=$1 and uid=$2 and comment_id=$3',
|
|
31
|
+
checklist: 'delete from crm.checklist where object_id=$1 and uid=$2 and checklist_id=$3 ',
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
const { rows, rowCount } = await pg.query(sql[type], [objectid, user.uid, id]);
|
|
35
|
+
return { data: { rows, rowCount }, user: { uid: user.uid, name: user.user_name } };
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
return { message: err.toString(), status: 500 };
|
|
39
|
+
}
|
|
40
|
+
}
|