@opengis/fastify-table 1.0.91 → 1.0.92
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 +22 -22
- package/crud/controllers/insert.js +58 -58
- package/crud/controllers/update.js +61 -61
- package/crud/funcs/dataDelete.js +19 -19
- package/crud/funcs/dataInsert.js +30 -30
- package/crud/funcs/dataUpdate.js +30 -29
- package/crud/funcs/getAccess.js +53 -53
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/setOpt.js +16 -16
- package/crud/funcs/utils/logChanges.js +71 -71
- package/crud/index.js +36 -36
- 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 +52 -52
- package/table/controllers/utils/getSelectMeta.js +2 -2
- package/table/controllers/utils/getTemplate.js +1 -1
- 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/test/api/widget.test.js +117 -117
- package/test/funcs/crud.test.js +122 -122
- package/util/controllers/properties.add.js +57 -57
- package/util/controllers/status.monitor.js +8 -8
- 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 +98 -98
- package/widget/controllers/widget.set.js +76 -76
- package/widget/index.js +40 -40
package/test/funcs/crud.test.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import config from '../config.js';
|
|
4
|
-
import pgClients from '../../pg/pgClients.js';
|
|
5
|
-
import rclient from '../../redis/client.js';
|
|
6
|
-
|
|
7
|
-
import dataInsert from '../../crud/funcs/dataInsert.js';
|
|
8
|
-
import dataUpdate from '../../crud/funcs/dataUpdate.js';
|
|
9
|
-
import dataDelete from '../../crud/funcs/dataDelete.js';
|
|
10
|
-
import logChanges from '../../crud/funcs/utils/logChanges.js';
|
|
11
|
-
import isFileExists from '../../crud/funcs/isFileExists.js';
|
|
12
|
-
|
|
13
|
-
import getOpt from '../../crud/funcs/getOpt.js';
|
|
14
|
-
import setOpt from '../../crud/funcs/setOpt.js';
|
|
15
|
-
|
|
16
|
-
import getToken from '../../crud/funcs/getToken.js';
|
|
17
|
-
import setToken from '../../crud/funcs/setToken.js';
|
|
18
|
-
|
|
19
|
-
test('funcs crud', async (t) => {
|
|
20
|
-
await pgClients.client.init();
|
|
21
|
-
await t.test('getOpt/setOpt', async () => {
|
|
22
|
-
const opt = await setOpt({ table: 'gis.dataset' });
|
|
23
|
-
const data = await getOpt(opt);
|
|
24
|
-
// console.log(data);
|
|
25
|
-
assert.equal(data.table, 'gis.dataset');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (config?.local) {
|
|
29
|
-
const id = (Math.random() * 10000).toFixed();
|
|
30
|
-
await t.test('dataInsert', async () => {
|
|
31
|
-
const data = await dataInsert({ table: 'gis.dataset', data: { dataset_id: id, dataset_name: '222' }, uid: '2' });
|
|
32
|
-
assert.equal(data.rows?.[0]?.dataset_id, id);
|
|
33
|
-
});
|
|
34
|
-
await t.test('dataUpdate', async () => {
|
|
35
|
-
const data = await dataUpdate({
|
|
36
|
-
table: 'gis.dataset', id, data: { dataset_name: '22211' }, uid: '2',
|
|
37
|
-
});
|
|
38
|
-
assert.equal(data.dataset_name, '22211');
|
|
39
|
-
});
|
|
40
|
-
await t.test('dataDelete', async () => {
|
|
41
|
-
const data = await dataDelete({ table: 'gis.dataset', id, uid: '2' });
|
|
42
|
-
assert.ok(data);
|
|
43
|
-
});
|
|
44
|
-
await t.test('clean up after test', async () => {
|
|
45
|
-
if (pgClients.client.pk?.['log.table_changes_data']) {
|
|
46
|
-
const { rowCount: testDatasets } = await pgClients.client.query('delete from gis.dataset where uid=$1', ['2']);
|
|
47
|
-
const { rowCount } = await pgClients.client.query('delete from log.table_changes_data where change_id in (select change_id from log.table_changes where entity_id=$1)', [id]);
|
|
48
|
-
const { rowCount: rowCount1 } = await pgClients.client.query('delete from log.table_changes where entity_id=$1', [id]);
|
|
49
|
-
console.log('CRUD test clean up', id, testDatasets, rowCount, rowCount1);
|
|
50
|
-
assert.ok(rowCount1);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (pgClients.client.pk?.['log.table_changes_data']) {
|
|
56
|
-
const id = (Math.random() * 10000).toFixed();
|
|
57
|
-
const name = '222';
|
|
58
|
-
await t.test('logChanges INSERT', async () => {
|
|
59
|
-
await pgClients.client.query(`insert into gis.dataset(dataset_id,dataset_name, uid) values($1,$2,$3) on conflict(dataset_id) do
|
|
60
|
-
update set dataset_name = excluded.dataset_name, uid = excluded.uid`, [id, name, '2']);
|
|
61
|
-
|
|
62
|
-
const data = await logChanges({
|
|
63
|
-
pg: pgClients.client, id, table: 'gis.dataset', data: { dataset_id: id, dataset_name: '222' }, uid: '2', type: 'INSERT',
|
|
64
|
-
});
|
|
65
|
-
assert.ok(data?.change_type === 'INSERT' && data?.entity_id === id && data?.new?.dataset_name === '222', typeof data === 'object' ? JSON.stringify(data) : data);
|
|
66
|
-
});
|
|
67
|
-
await t.test('logChanges UPDATE', async () => {
|
|
68
|
-
/* await pgClients.client.query('update gis.dataset(dataset_id,dataset_name) set dataset_name=$', [id, name]); */
|
|
69
|
-
const data = await logChanges({
|
|
70
|
-
pg: pgClients.client, id, table: 'gis.dataset', data: { dataset_id: id, dataset_name: '2222' }, uid: '2', type: 'UPDATE',
|
|
71
|
-
});
|
|
72
|
-
assert.ok(data?.change_type === 'UPDATE' && data?.entity_id === id && data?.new?.dataset_name === '2222' && data?.old?.dataset_name === '222', typeof data === 'object' ? JSON.stringify(data) : data);
|
|
73
|
-
});
|
|
74
|
-
await t.test('logChanges DELETE', async () => {
|
|
75
|
-
const data = await logChanges({
|
|
76
|
-
pg: pgClients.client, id, table: 'gis.dataset', uid: '2', type: 'DELETE',
|
|
77
|
-
});
|
|
78
|
-
assert.ok(data?.change_type === 'DELETE' && data?.old?.dataset_id === id, typeof data === 'object' ? JSON.stringify(data) : data);
|
|
79
|
-
});
|
|
80
|
-
await t.test('clean up after test', async () => {
|
|
81
|
-
const { rowCount: testDatasets } = await pgClients.client.query('delete from gis.dataset where uid=$1', ['2']);
|
|
82
|
-
const { rowCount } = await pgClients.client.query('delete from log.table_changes_data where change_id in (select change_id from log.table_changes where entity_id=$1)', [id]);
|
|
83
|
-
const { rowCount: rowCount1 } = await pgClients.client.query('delete from log.table_changes where entity_id=$1', [id]);
|
|
84
|
-
console.log('logChanges test clean up', id, testDatasets, rowCount, rowCount1);
|
|
85
|
-
assert.ok(rowCount1);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
await t.test('isFileExists', async () => {
|
|
90
|
-
const data = await isFileExists({ filepath: '../../crud/funcs/isFileExists.js' });
|
|
91
|
-
assert.equal(data, false);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
let tokens;
|
|
95
|
-
// const session = { passport: { user: { uid: '1' } } };
|
|
96
|
-
const tokenData = JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' });
|
|
97
|
-
|
|
98
|
-
await t.test('setToken', async () => {
|
|
99
|
-
tokens = setToken({
|
|
100
|
-
funcs: { config },
|
|
101
|
-
ids: [tokenData],
|
|
102
|
-
mode: 'a',
|
|
103
|
-
uid: 1,
|
|
104
|
-
array: 1,
|
|
105
|
-
});
|
|
106
|
-
assert.equal(tokens.length, 1);
|
|
107
|
-
});
|
|
108
|
-
await t.test('getToken', async () => {
|
|
109
|
-
const data = await getToken({
|
|
110
|
-
uid: 1,
|
|
111
|
-
token: tokens[0],
|
|
112
|
-
mode: 'a',
|
|
113
|
-
});
|
|
114
|
-
assert.equal(data, tokenData);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// pgClients.client.query('delete from gis.dataset where dataset_id=$1', [id]);
|
|
118
|
-
t.after(() => {
|
|
119
|
-
pgClients.client?.end();
|
|
120
|
-
rclient.quit();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import config from '../config.js';
|
|
4
|
+
import pgClients from '../../pg/pgClients.js';
|
|
5
|
+
import rclient from '../../redis/client.js';
|
|
6
|
+
|
|
7
|
+
import dataInsert from '../../crud/funcs/dataInsert.js';
|
|
8
|
+
import dataUpdate from '../../crud/funcs/dataUpdate.js';
|
|
9
|
+
import dataDelete from '../../crud/funcs/dataDelete.js';
|
|
10
|
+
import logChanges from '../../crud/funcs/utils/logChanges.js';
|
|
11
|
+
import isFileExists from '../../crud/funcs/isFileExists.js';
|
|
12
|
+
|
|
13
|
+
import getOpt from '../../crud/funcs/getOpt.js';
|
|
14
|
+
import setOpt from '../../crud/funcs/setOpt.js';
|
|
15
|
+
|
|
16
|
+
import getToken from '../../crud/funcs/getToken.js';
|
|
17
|
+
import setToken from '../../crud/funcs/setToken.js';
|
|
18
|
+
|
|
19
|
+
test('funcs crud', async (t) => {
|
|
20
|
+
await pgClients.client.init();
|
|
21
|
+
await t.test('getOpt/setOpt', async () => {
|
|
22
|
+
const opt = await setOpt({ table: 'gis.dataset' });
|
|
23
|
+
const data = await getOpt(opt);
|
|
24
|
+
// console.log(data);
|
|
25
|
+
assert.equal(data.table, 'gis.dataset');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (config?.local) {
|
|
29
|
+
const id = (Math.random() * 10000).toFixed();
|
|
30
|
+
await t.test('dataInsert', async () => {
|
|
31
|
+
const data = await dataInsert({ table: 'gis.dataset', data: { dataset_id: id, dataset_name: '222' }, uid: '2' });
|
|
32
|
+
assert.equal(data.rows?.[0]?.dataset_id, id);
|
|
33
|
+
});
|
|
34
|
+
await t.test('dataUpdate', async () => {
|
|
35
|
+
const data = await dataUpdate({
|
|
36
|
+
table: 'gis.dataset', id, data: { dataset_name: '22211' }, uid: '2',
|
|
37
|
+
});
|
|
38
|
+
assert.equal(data.dataset_name, '22211');
|
|
39
|
+
});
|
|
40
|
+
await t.test('dataDelete', async () => {
|
|
41
|
+
const data = await dataDelete({ table: 'gis.dataset', id, uid: '2' });
|
|
42
|
+
assert.ok(data);
|
|
43
|
+
});
|
|
44
|
+
await t.test('clean up after test', async () => {
|
|
45
|
+
if (pgClients.client.pk?.['log.table_changes_data']) {
|
|
46
|
+
const { rowCount: testDatasets } = await pgClients.client.query('delete from gis.dataset where uid=$1', ['2']);
|
|
47
|
+
const { rowCount } = await pgClients.client.query('delete from log.table_changes_data where change_id in (select change_id from log.table_changes where entity_id=$1)', [id]);
|
|
48
|
+
const { rowCount: rowCount1 } = await pgClients.client.query('delete from log.table_changes where entity_id=$1', [id]);
|
|
49
|
+
console.log('CRUD test clean up', id, testDatasets, rowCount, rowCount1);
|
|
50
|
+
assert.ok(rowCount1);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (pgClients.client.pk?.['log.table_changes_data']) {
|
|
56
|
+
const id = (Math.random() * 10000).toFixed();
|
|
57
|
+
const name = '222';
|
|
58
|
+
await t.test('logChanges INSERT', async () => {
|
|
59
|
+
await pgClients.client.query(`insert into gis.dataset(dataset_id,dataset_name, uid) values($1,$2,$3) on conflict(dataset_id) do
|
|
60
|
+
update set dataset_name = excluded.dataset_name, uid = excluded.uid`, [id, name, '2']);
|
|
61
|
+
|
|
62
|
+
const data = await logChanges({
|
|
63
|
+
pg: pgClients.client, id, table: 'gis.dataset', data: { dataset_id: id, dataset_name: '222' }, uid: '2', type: 'INSERT',
|
|
64
|
+
});
|
|
65
|
+
assert.ok(data?.change_type === 'INSERT' && data?.entity_id === id && data?.new?.dataset_name === '222', typeof data === 'object' ? JSON.stringify(data) : data);
|
|
66
|
+
});
|
|
67
|
+
await t.test('logChanges UPDATE', async () => {
|
|
68
|
+
/* await pgClients.client.query('update gis.dataset(dataset_id,dataset_name) set dataset_name=$', [id, name]); */
|
|
69
|
+
const data = await logChanges({
|
|
70
|
+
pg: pgClients.client, id, table: 'gis.dataset', data: { dataset_id: id, dataset_name: '2222' }, uid: '2', type: 'UPDATE',
|
|
71
|
+
});
|
|
72
|
+
assert.ok(data?.change_type === 'UPDATE' && data?.entity_id === id && data?.new?.dataset_name === '2222' && data?.old?.dataset_name === '222', typeof data === 'object' ? JSON.stringify(data) : data);
|
|
73
|
+
});
|
|
74
|
+
await t.test('logChanges DELETE', async () => {
|
|
75
|
+
const data = await logChanges({
|
|
76
|
+
pg: pgClients.client, id, table: 'gis.dataset', uid: '2', type: 'DELETE',
|
|
77
|
+
});
|
|
78
|
+
assert.ok(data?.change_type === 'DELETE' && data?.old?.dataset_id === id, typeof data === 'object' ? JSON.stringify(data) : data);
|
|
79
|
+
});
|
|
80
|
+
await t.test('clean up after test', async () => {
|
|
81
|
+
const { rowCount: testDatasets } = await pgClients.client.query('delete from gis.dataset where uid=$1', ['2']);
|
|
82
|
+
const { rowCount } = await pgClients.client.query('delete from log.table_changes_data where change_id in (select change_id from log.table_changes where entity_id=$1)', [id]);
|
|
83
|
+
const { rowCount: rowCount1 } = await pgClients.client.query('delete from log.table_changes where entity_id=$1', [id]);
|
|
84
|
+
console.log('logChanges test clean up', id, testDatasets, rowCount, rowCount1);
|
|
85
|
+
assert.ok(rowCount1);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
await t.test('isFileExists', async () => {
|
|
90
|
+
const data = await isFileExists({ filepath: '../../crud/funcs/isFileExists.js' });
|
|
91
|
+
assert.equal(data, false);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
let tokens;
|
|
95
|
+
// const session = { passport: { user: { uid: '1' } } };
|
|
96
|
+
const tokenData = JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' });
|
|
97
|
+
|
|
98
|
+
await t.test('setToken', async () => {
|
|
99
|
+
tokens = setToken({
|
|
100
|
+
funcs: { config },
|
|
101
|
+
ids: [tokenData],
|
|
102
|
+
mode: 'a',
|
|
103
|
+
uid: 1,
|
|
104
|
+
array: 1,
|
|
105
|
+
});
|
|
106
|
+
assert.equal(tokens.length, 1);
|
|
107
|
+
});
|
|
108
|
+
await t.test('getToken', async () => {
|
|
109
|
+
const data = await getToken({
|
|
110
|
+
uid: 1,
|
|
111
|
+
token: tokens[0],
|
|
112
|
+
mode: 'a',
|
|
113
|
+
});
|
|
114
|
+
assert.equal(data, tokenData);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// pgClients.client.query('delete from gis.dataset where dataset_id=$1', [id]);
|
|
118
|
+
t.after(() => {
|
|
119
|
+
pgClients.client?.end();
|
|
120
|
+
rclient.quit();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import dataInsert from '../../crud/funcs/dataInsert.js';
|
|
2
|
-
|
|
3
|
-
const table = 'crm.properties';
|
|
4
|
-
|
|
5
|
-
function checkKeyType({ body, key }) {
|
|
6
|
-
if (typeof body[key] === 'number' && (!/\D/.test(body[key].toString()) && body[key].toString().length < 10)) {
|
|
7
|
-
return { [key]: 'int' };
|
|
8
|
-
} if (typeof body[key] === 'object') {
|
|
9
|
-
return { [key]: 'json' };
|
|
10
|
-
}
|
|
11
|
-
if (Date.parse(body[key], 'yyyy/MM/ddTHH:mm:ss.000Z')) {
|
|
12
|
-
return { [key]: 'date' };
|
|
13
|
-
}
|
|
14
|
-
return { [key]: 'text' };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default async function addExtraProperties({
|
|
18
|
-
pg, funcs, params = {}, body = {}, user = {},
|
|
19
|
-
}) {
|
|
20
|
-
const { id } = params;
|
|
21
|
-
if (!id) {
|
|
22
|
-
return { message: 'not enougn params: 1', status: 400 };
|
|
23
|
-
}
|
|
24
|
-
const extraProperties = Object.keys(body);
|
|
25
|
-
if (!extraProperties.length) {
|
|
26
|
-
return { message: 'not enougn params: 2', status: 400 };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!pg.pk?.[table]) {
|
|
30
|
-
return { message: 'table not found: crm.properties', status: 400 };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
const uid = funcs.config?.auth?.disable ? '1' : user.uid;
|
|
35
|
-
await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
|
|
36
|
-
const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
|
|
37
|
-
const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
|
|
38
|
-
const propertyType = keyTypeMatch[key];
|
|
39
|
-
const { rows = [] } = await dataInsert({
|
|
40
|
-
pg,
|
|
41
|
-
table,
|
|
42
|
-
data: {
|
|
43
|
-
property_type: propertyType,
|
|
44
|
-
property_key: key,
|
|
45
|
-
object_id: id,
|
|
46
|
-
[`property_${propertyType}`]: body[key],
|
|
47
|
-
},
|
|
48
|
-
uid,
|
|
49
|
-
});
|
|
50
|
-
return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
|
|
51
|
-
}));
|
|
52
|
-
return { message: { rows: res }, status: 200 };
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
return { error: err.toString(), status: 500 };
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import dataInsert from '../../crud/funcs/dataInsert.js';
|
|
2
|
+
|
|
3
|
+
const table = 'crm.properties';
|
|
4
|
+
|
|
5
|
+
function checkKeyType({ body, key }) {
|
|
6
|
+
if (typeof body[key] === 'number' && (!/\D/.test(body[key].toString()) && body[key].toString().length < 10)) {
|
|
7
|
+
return { [key]: 'int' };
|
|
8
|
+
} if (typeof body[key] === 'object') {
|
|
9
|
+
return { [key]: 'json' };
|
|
10
|
+
}
|
|
11
|
+
if (Date.parse(body[key], 'yyyy/MM/ddTHH:mm:ss.000Z')) {
|
|
12
|
+
return { [key]: 'date' };
|
|
13
|
+
}
|
|
14
|
+
return { [key]: 'text' };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default async function addExtraProperties({
|
|
18
|
+
pg, funcs, params = {}, body = {}, user = {},
|
|
19
|
+
}) {
|
|
20
|
+
const { id } = params;
|
|
21
|
+
if (!id) {
|
|
22
|
+
return { message: 'not enougn params: 1', status: 400 };
|
|
23
|
+
}
|
|
24
|
+
const extraProperties = Object.keys(body);
|
|
25
|
+
if (!extraProperties.length) {
|
|
26
|
+
return { message: 'not enougn params: 2', status: 400 };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!pg.pk?.[table]) {
|
|
30
|
+
return { message: 'table not found: crm.properties', status: 400 };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const uid = funcs.config?.auth?.disable ? '1' : user.uid;
|
|
35
|
+
await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
|
|
36
|
+
const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
|
|
37
|
+
const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
|
|
38
|
+
const propertyType = keyTypeMatch[key];
|
|
39
|
+
const { rows = [] } = await dataInsert({
|
|
40
|
+
pg,
|
|
41
|
+
table,
|
|
42
|
+
data: {
|
|
43
|
+
property_type: propertyType,
|
|
44
|
+
property_key: key,
|
|
45
|
+
object_id: id,
|
|
46
|
+
[`property_${propertyType}`]: body[key],
|
|
47
|
+
},
|
|
48
|
+
uid,
|
|
49
|
+
});
|
|
50
|
+
return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
|
|
51
|
+
}));
|
|
52
|
+
return { message: { rows: res }, status: 200 };
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
return { error: err.toString(), status: 500 };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|