@opengis/fastify-table 1.0.76 → 1.0.78
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 +5 -1
- 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/getAccess.js +53 -53
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/setOpt.js +16 -16
- package/helper.js +28 -28
- 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 +82 -82
- 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 +64 -64
- 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/server/templates/table/test.gis.map.table.json +44 -44
- package/table/controllers/data.js +95 -95
- package/table/controllers/utils/getSelect.js +20 -20
- 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/metaFormat/getSelectVal.js +20 -20
- package/test/api/crud.test.js +88 -88
- package/util/controllers/status.monitor.js +8 -3
- package/util/index.js +21 -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
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import getSelect from '../../controllers/utils/getSelect.js';
|
|
2
|
-
import pg from '../../../pg/pgClients.js';
|
|
3
|
-
import redis from '../../../redis/client.js';
|
|
4
|
-
|
|
5
|
-
export default async function metaFormat({ name, values }) {
|
|
6
|
-
const cls = await getSelect(name);
|
|
7
|
-
if (!cls?.arr && !cls?.sql) return null;
|
|
8
|
-
const key = `select:${name}`;
|
|
9
|
-
const cache = !cls.arr ? (await redis.hmget(key, values)).reduce((p, el, i) => ({ ...p, [values[i]]: el }), {}) : {};
|
|
10
|
-
|
|
11
|
-
const data = cls.arr || (values.filter(el => !cache[el]).length
|
|
12
|
-
? await pg.client.query(`with c(id,text) as (${cls.sql}) select * from c where id = any('{${values.filter(el => !cache[el])}}')`).then(el => el.rows)
|
|
13
|
-
: []);
|
|
14
|
-
|
|
15
|
-
const clsAr = { ...cache, ...data.reduce((p, el) => ({ ...p, [el.id.toString()]: el.color ? el : el.text }), {}) };
|
|
16
|
-
if (!cls.arr && data.length) {
|
|
17
|
-
redis.hmset(key, clsAr);
|
|
18
|
-
}
|
|
19
|
-
return clsAr;
|
|
20
|
-
}
|
|
1
|
+
import getSelect from '../../controllers/utils/getSelect.js';
|
|
2
|
+
import pg from '../../../pg/pgClients.js';
|
|
3
|
+
import redis from '../../../redis/client.js';
|
|
4
|
+
|
|
5
|
+
export default async function metaFormat({ name, values }) {
|
|
6
|
+
const cls = await getSelect(name);
|
|
7
|
+
if (!cls?.arr && !cls?.sql) return null;
|
|
8
|
+
const key = `select:${name}`;
|
|
9
|
+
const cache = !cls.arr ? (await redis.hmget(key, values)).reduce((p, el, i) => ({ ...p, [values[i]]: el }), {}) : {};
|
|
10
|
+
|
|
11
|
+
const data = cls.arr || (values.filter(el => !cache[el]).length
|
|
12
|
+
? await pg.client.query(`with c(id,text) as (${cls.sql}) select * from c where id = any('{${values.filter(el => !cache[el])}}')`).then(el => el.rows)
|
|
13
|
+
: []);
|
|
14
|
+
|
|
15
|
+
const clsAr = { ...cache, ...data.reduce((p, el) => ({ ...p, [el.id.toString()]: el.color ? el : el.text }), {}) };
|
|
16
|
+
if (!cls.arr && data.length) {
|
|
17
|
+
redis.hmset(key, clsAr);
|
|
18
|
+
}
|
|
19
|
+
return clsAr;
|
|
20
|
+
}
|
package/test/api/crud.test.js
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../../helper.js';
|
|
5
|
-
|
|
6
|
-
import config from '../config.js';
|
|
7
|
-
import pgClients from '../../pg/pgClients.js';
|
|
8
|
-
|
|
9
|
-
const mapId = '5400000';
|
|
10
|
-
|
|
11
|
-
test('api crud', async (t) => {
|
|
12
|
-
const app = await build(t);
|
|
13
|
-
const prefix = config.prefix || '/api';
|
|
14
|
-
|
|
15
|
-
// delete old test data before test
|
|
16
|
-
const { rowCount } = await pgClients.client.query('delete from gis.map where map_id=$1', [mapId]);
|
|
17
|
-
console.log(rowCount);
|
|
18
|
-
|
|
19
|
-
app.addHook('onRequest', async (req) => {
|
|
20
|
-
req.session = { passport: { user: { uid: '1' } } };
|
|
21
|
-
req.user = req.session.passport.user;
|
|
22
|
-
req.uid = req.user.uid;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
await t.test('POST /insert', async () => {
|
|
26
|
-
const res = await app.inject({
|
|
27
|
-
method: 'POST',
|
|
28
|
-
url: `${prefix}/table/test.gis.map.table`,
|
|
29
|
-
body: {
|
|
30
|
-
alias: 'testMap',
|
|
31
|
-
map_id: mapId,
|
|
32
|
-
ord: 1,
|
|
33
|
-
enabled: false,
|
|
34
|
-
tags: ['unit', 'test'],
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
// console.log(res);
|
|
38
|
-
assert.ok(res.json().rows ? res.json().rows[0]?.map_id : res.json().map_id, res.json().status);
|
|
39
|
-
assert.ok(111);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
await t.test('POST /properties/:id', async () => {
|
|
43
|
-
const res = await app.inject({
|
|
44
|
-
method: 'POST',
|
|
45
|
-
url: `${prefix}/properties/${mapId}`,
|
|
46
|
-
body: {
|
|
47
|
-
custom_alias: 'testMap',
|
|
48
|
-
custom_ord: 5,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
assert.ok(res.json().message?.rows?.length, res.json().status);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
await t.test('GET /properties/:id', async () => {
|
|
55
|
-
const res = await app.inject({
|
|
56
|
-
method: 'GET',
|
|
57
|
-
url: `${prefix}/properties/${mapId}`,
|
|
58
|
-
});
|
|
59
|
-
assert.ok(res.json().message?.custom_alias, res.json().status);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
await t.test('PUT /update', async () => {
|
|
63
|
-
const res = await app.inject({
|
|
64
|
-
method: 'PUT',
|
|
65
|
-
url: `${prefix}/table/test.gis.map.table/${mapId}`,
|
|
66
|
-
body: {
|
|
67
|
-
editor_id: '11',
|
|
68
|
-
alias: 'testMapEdit',
|
|
69
|
-
map_id: mapId,
|
|
70
|
-
ord: 2,
|
|
71
|
-
enabled: true,
|
|
72
|
-
tags: ['unittest'],
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
// console.log(res);
|
|
76
|
-
assert.ok((res.json().rows ? res.json().rows[0]?.editor_id : res.json().editor_id) === '11', res.json().status);
|
|
77
|
-
assert.ok(11);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
await t.test('DELETE /delete', async () => {
|
|
81
|
-
const res = await app.inject({
|
|
82
|
-
method: 'DELETE',
|
|
83
|
-
url: `${prefix}/table/test.gis.map.table/${mapId}`,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
assert.ok(res.json().msg?.map_id === mapId, res.json().status);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../../helper.js';
|
|
5
|
+
|
|
6
|
+
import config from '../config.js';
|
|
7
|
+
import pgClients from '../../pg/pgClients.js';
|
|
8
|
+
|
|
9
|
+
const mapId = '5400000';
|
|
10
|
+
|
|
11
|
+
test('api crud', async (t) => {
|
|
12
|
+
const app = await build(t);
|
|
13
|
+
const prefix = config.prefix || '/api';
|
|
14
|
+
|
|
15
|
+
// delete old test data before test
|
|
16
|
+
const { rowCount } = await pgClients.client.query('delete from gis.map where map_id=$1', [mapId]);
|
|
17
|
+
console.log(rowCount);
|
|
18
|
+
|
|
19
|
+
app.addHook('onRequest', async (req) => {
|
|
20
|
+
req.session = { passport: { user: { uid: '1' } } };
|
|
21
|
+
req.user = req.session.passport.user;
|
|
22
|
+
req.uid = req.user.uid;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await t.test('POST /insert', async () => {
|
|
26
|
+
const res = await app.inject({
|
|
27
|
+
method: 'POST',
|
|
28
|
+
url: `${prefix}/table/test.gis.map.table`,
|
|
29
|
+
body: {
|
|
30
|
+
alias: 'testMap',
|
|
31
|
+
map_id: mapId,
|
|
32
|
+
ord: 1,
|
|
33
|
+
enabled: false,
|
|
34
|
+
tags: ['unit', 'test'],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
// console.log(res);
|
|
38
|
+
assert.ok(res.json().rows ? res.json().rows[0]?.map_id : res.json().map_id, res.json().status);
|
|
39
|
+
assert.ok(111);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await t.test('POST /properties/:id', async () => {
|
|
43
|
+
const res = await app.inject({
|
|
44
|
+
method: 'POST',
|
|
45
|
+
url: `${prefix}/properties/${mapId}`,
|
|
46
|
+
body: {
|
|
47
|
+
custom_alias: 'testMap',
|
|
48
|
+
custom_ord: 5,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
assert.ok(res.json().message?.rows?.length, res.json().status);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await t.test('GET /properties/:id', async () => {
|
|
55
|
+
const res = await app.inject({
|
|
56
|
+
method: 'GET',
|
|
57
|
+
url: `${prefix}/properties/${mapId}`,
|
|
58
|
+
});
|
|
59
|
+
assert.ok(res.json().message?.custom_alias, res.json().status);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await t.test('PUT /update', async () => {
|
|
63
|
+
const res = await app.inject({
|
|
64
|
+
method: 'PUT',
|
|
65
|
+
url: `${prefix}/table/test.gis.map.table/${mapId}`,
|
|
66
|
+
body: {
|
|
67
|
+
editor_id: '11',
|
|
68
|
+
alias: 'testMapEdit',
|
|
69
|
+
map_id: mapId,
|
|
70
|
+
ord: 2,
|
|
71
|
+
enabled: true,
|
|
72
|
+
tags: ['unittest'],
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
// console.log(res);
|
|
76
|
+
assert.ok((res.json().rows ? res.json().rows[0]?.editor_id : res.json().editor_id) === '11', res.json().status);
|
|
77
|
+
assert.ok(11);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
await t.test('DELETE /delete', async () => {
|
|
81
|
+
const res = await app.inject({
|
|
82
|
+
method: 'DELETE',
|
|
83
|
+
url: `${prefix}/table/test.gis.map.table/${mapId}`,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
assert.ok(res.json().msg?.map_id === mapId, res.json().status);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
}
|
package/util/index.js
CHANGED
|
@@ -1,21 +1,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
|
-
|
|
6
|
-
const propertiesSchema = {
|
|
7
|
-
params: {
|
|
8
|
-
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
async function plugin(fastify, config = {}) {
|
|
13
|
-
const prefix = config.prefix || '/api';
|
|
14
|
-
|
|
15
|
-
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
16
|
-
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
17
|
-
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
18
|
-
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default plugin;
|
|
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
|
+
const propertiesSchema = {
|
|
7
|
+
params: {
|
|
8
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
async function plugin(fastify, config = {}) {
|
|
13
|
+
const prefix = config.prefix || '/api';
|
|
14
|
+
|
|
15
|
+
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
16
|
+
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
17
|
+
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
18
|
+
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
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
|
+
}
|