@opengis/fastify-table 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +42 -42
- package/Changelog.md +47 -47
- package/README.md +26 -26
- package/config.js +11 -11
- package/crud/controllers/deleteCrud.js +10 -10
- package/crud/controllers/insert.js +28 -28
- package/crud/controllers/update.js +29 -29
- package/crud/controllers/utils/checkXSS.js +45 -45
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/dataDelete.js +15 -15
- package/crud/funcs/dataInsert.js +24 -24
- package/crud/funcs/getIdByToken.js +29 -29
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setTokenById.js +55 -55
- package/helper.js +28 -28
- package/index.js +32 -32
- package/package.json +22 -22
- package/pg/funcs/autoIndex.js +89 -89
- package/pg/funcs/getMeta.js +27 -27
- package/pg/funcs/init.js +42 -42
- package/pg/funcs/pgClients.js +2 -2
- package/pg/index.js +35 -35
- package/pg/pgClients.js +17 -17
- 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/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/templates/form/test.dataset.form.json +411 -411
- package/server.js +14 -14
- package/table/controllers/data.js +57 -55
- package/table/controllers/filter.js +32 -24
- 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/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/index.js +28 -0
- package/table/index.js +17 -14
- package/test/api/crud.test.js +50 -50
- package/test/api/crud.xss.test.js +70 -70
- package/test/api/table.test.js +49 -49
- package/test/config.example +18 -18
- package/test/funcs/crud.test.js +77 -77
- package/test/funcs/pg.test.js +32 -32
- package/test/funcs/redis.test.js +19 -19
- package/test/funcs/table.test.js +48 -48
- package/test/templates/cls/itree.recommend.json +26 -0
- package/test/templates/cls/itree.type_plant.json +65 -0
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +3 -3
- package/test/templates/select/contact_id.sql +1 -0
- package/test/templates/select/storage.data.json +2 -2
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/test/templates/table/green_space.table.json +3 -3
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
function getTable(table) {
|
|
2
|
-
const result = table?.toLowerCase()?.replace(/[\n\r]+/g, ' ')?.split(' from ')?.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
3
|
-
?.map((el) => el.split(/[ )]/)[0]);
|
|
4
|
-
return result;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
|
|
9
|
-
* @param {String} opt.query - запит до таблиці
|
|
10
|
-
* @param {String} opt.hash - інформація з хешу по запиту
|
|
11
|
-
*/
|
|
12
|
-
const tableSql = {};
|
|
13
|
-
async function getTableSql({
|
|
14
|
-
pg, body, table, fields,
|
|
15
|
-
}) {
|
|
16
|
-
if (tableSql[table]) return tableSql[table];
|
|
17
|
-
|
|
18
|
-
const fieldList = fields.map((el) => el.name);
|
|
19
|
-
|
|
20
|
-
const tableList = body?.sql?.map((el) => getTable(el.sql)).reduce((acc, el) => acc.concat(el), []).filter((el) => fieldList.includes(pg.pk[el]));
|
|
21
|
-
|
|
22
|
-
if (!tableList) { tableSql[table] = []; return []; }
|
|
23
|
-
|
|
24
|
-
const data = await Promise.all(tableList?.map(async (tableEl) => {
|
|
25
|
-
const { fields: fieldsEl } = await pg.query(`select * from ${tableEl} limit 0`, { cache: 1 });
|
|
26
|
-
return fieldsEl.map((el) => ({ name: el.name, table: tableEl, pk: pg.pk[tableEl] }));
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
tableSql[table] = data.reduce((acc, el) => acc.concat(el), []);
|
|
30
|
-
|
|
31
|
-
return tableSql[table];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default getTableSql;
|
|
1
|
+
function getTable(table) {
|
|
2
|
+
const result = table?.toLowerCase()?.replace(/[\n\r]+/g, ' ')?.split(' from ')?.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
3
|
+
?.map((el) => el.split(/[ )]/)[0]);
|
|
4
|
+
return result;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
|
|
9
|
+
* @param {String} opt.query - запит до таблиці
|
|
10
|
+
* @param {String} opt.hash - інформація з хешу по запиту
|
|
11
|
+
*/
|
|
12
|
+
const tableSql = {};
|
|
13
|
+
async function getTableSql({
|
|
14
|
+
pg, body, table, fields,
|
|
15
|
+
}) {
|
|
16
|
+
if (tableSql[table]) return tableSql[table];
|
|
17
|
+
|
|
18
|
+
const fieldList = fields.map((el) => el.name);
|
|
19
|
+
|
|
20
|
+
const tableList = body?.sql?.map((el) => getTable(el.sql)).reduce((acc, el) => acc.concat(el), []).filter((el) => fieldList.includes(pg.pk[el]));
|
|
21
|
+
|
|
22
|
+
if (!tableList) { tableSql[table] = []; return []; }
|
|
23
|
+
|
|
24
|
+
const data = await Promise.all(tableList?.map(async (tableEl) => {
|
|
25
|
+
const { fields: fieldsEl } = await pg.query(`select * from ${tableEl} limit 0`, { cache: 1 });
|
|
26
|
+
return fieldsEl.map((el) => ({ name: el.name, table: tableEl, pk: pg.pk[tableEl] }));
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
tableSql[table] = data.reduce((acc, el) => acc.concat(el), []);
|
|
30
|
+
|
|
31
|
+
return tableSql[table];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default getTableSql;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import getTemplate from '../../controllers/utils/getTemplate.js';
|
|
2
|
+
import getSelect from '../../controllers/utils/getSelect.js';
|
|
3
|
+
import pg from '../../../pg/pgClients.js';
|
|
4
|
+
|
|
5
|
+
export default async function metaFormat({ rows, table }) {
|
|
6
|
+
const loadTable = await getTemplate('table', table);
|
|
7
|
+
const selectCols = loadTable.columns?.filter((e) => e.data);
|
|
8
|
+
|
|
9
|
+
// cls & select format
|
|
10
|
+
|
|
11
|
+
await Promise.all(selectCols?.map(async (attr) => {
|
|
12
|
+
const val = [...new Set(rows?.map((el) => el[attr.name]).flat())];
|
|
13
|
+
if (!val.filter((el) => el).length) return null;
|
|
14
|
+
const cls = await getSelect(attr.data);
|
|
15
|
+
if (!cls?.arr && !cls?.sql) return null;
|
|
16
|
+
|
|
17
|
+
const data = cls.arr || await pg.client.query(`with c(id,text) as (${cls.sql}) select * from c where id = any('{${val}}')`).then(el => el.rows);
|
|
18
|
+
|
|
19
|
+
const clsAr = data.reduce((p, el) => ({ ...p, [el.id.toString()]: el.text }), {});
|
|
20
|
+
rows.forEach(el => {
|
|
21
|
+
Object.assign(el, { [`${attr.name}_text`]: clsAr[el[attr.name]] || el[attr.name] });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return null;
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
return rows;
|
|
28
|
+
}
|
package/table/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import suggest from './controllers/suggest.js';
|
|
2
|
-
import data from './controllers/data.js';
|
|
3
|
-
import filter from './controllers/filter.js';
|
|
4
|
-
import form from './controllers/form.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
fastify.
|
|
10
|
-
|
|
11
|
-
fastify.get(`${prefix}/
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import suggest from './controllers/suggest.js';
|
|
2
|
+
import data from './controllers/data.js';
|
|
3
|
+
import filter from './controllers/filter.js';
|
|
4
|
+
import form from './controllers/form.js';
|
|
5
|
+
import metaFormat from './funcs/metaFormat/index.js';
|
|
6
|
+
|
|
7
|
+
async function plugin(fastify, config = {}) {
|
|
8
|
+
const prefix = config.prefix || '/api';
|
|
9
|
+
fastify.decorate('metaFormat', metaFormat);
|
|
10
|
+
|
|
11
|
+
fastify.get(`${prefix}/suggest/:data`, {}, suggest);
|
|
12
|
+
fastify.get(`${prefix}/data/:table/:id?`, {}, data); // vs.crm.data.api с node
|
|
13
|
+
fastify.get(`${prefix}/filter/:table`, {}, filter);
|
|
14
|
+
fastify.get(`${prefix}/form/:form`, {}, form);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default plugin;
|
package/test/api/crud.test.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
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
|
-
|
|
8
|
-
test('api crud', async (t) => {
|
|
9
|
-
const app = await build(t);
|
|
10
|
-
const prefix = config.prefix || '/api';
|
|
11
|
-
|
|
12
|
-
await t.test('POST /insert', async () => {
|
|
13
|
-
const res = await app.inject({
|
|
14
|
-
method: 'POST',
|
|
15
|
-
url: `${prefix}/crud/gis.dataset`,
|
|
16
|
-
body: { dataset_name: '111', dataset_id: '5400000' },
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const rep = JSON.parse(res?.body);
|
|
20
|
-
// rep.dataset_id
|
|
21
|
-
// console.log(rep);
|
|
22
|
-
// pgClients.client.query('delete from gis.dataset where dataset_id=$1', [rep.dataset_id]);
|
|
23
|
-
assert.ok(rep.dataset_id);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
await t.test('PUT /update', async () => {
|
|
27
|
-
const res = await app.inject({
|
|
28
|
-
method: 'PUT',
|
|
29
|
-
url: `${prefix}/crud/gis.dataset/5400000`,
|
|
30
|
-
body: { editor_id: '11' },
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const rep = JSON.parse(res?.body);
|
|
34
|
-
// rep.dataset_id
|
|
35
|
-
// console.log(rep);
|
|
36
|
-
assert.equal(rep.editor_id, '11');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
await t.test('DELETE /delete', async () => {
|
|
40
|
-
const res = await app.inject({
|
|
41
|
-
method: 'DELETE',
|
|
42
|
-
url: `${prefix}/crud/gis.dataset/5400000`,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const rep = JSON.parse(res?.body);
|
|
46
|
-
// rep.dataset_id
|
|
47
|
-
// console.log(rep);
|
|
48
|
-
assert.ok(rep);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
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
|
+
|
|
8
|
+
test('api crud', async (t) => {
|
|
9
|
+
const app = await build(t);
|
|
10
|
+
const prefix = config.prefix || '/api';
|
|
11
|
+
|
|
12
|
+
await t.test('POST /insert', async () => {
|
|
13
|
+
const res = await app.inject({
|
|
14
|
+
method: 'POST',
|
|
15
|
+
url: `${prefix}/crud/gis.dataset`,
|
|
16
|
+
body: { dataset_name: '111', dataset_id: '5400000' },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const rep = JSON.parse(res?.body);
|
|
20
|
+
// rep.dataset_id
|
|
21
|
+
// console.log(rep);
|
|
22
|
+
// pgClients.client.query('delete from gis.dataset where dataset_id=$1', [rep.dataset_id]);
|
|
23
|
+
assert.ok(rep.dataset_id);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await t.test('PUT /update', async () => {
|
|
27
|
+
const res = await app.inject({
|
|
28
|
+
method: 'PUT',
|
|
29
|
+
url: `${prefix}/crud/gis.dataset/5400000`,
|
|
30
|
+
body: { editor_id: '11' },
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const rep = JSON.parse(res?.body);
|
|
34
|
+
// rep.dataset_id
|
|
35
|
+
// console.log(rep);
|
|
36
|
+
assert.equal(rep.editor_id, '11');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await t.test('DELETE /delete', async () => {
|
|
40
|
+
const res = await app.inject({
|
|
41
|
+
method: 'DELETE',
|
|
42
|
+
url: `${prefix}/crud/gis.dataset/5400000`,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const rep = JSON.parse(res?.body);
|
|
46
|
+
// rep.dataset_id
|
|
47
|
+
// console.log(rep);
|
|
48
|
+
assert.ok(rep);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../../helper.js';
|
|
5
|
-
|
|
6
|
-
import setTokenById from '../../crud/funcs/setTokenById.js';
|
|
7
|
-
import config from '../config.js';
|
|
8
|
-
|
|
9
|
-
test('api crud xss', async (t) => {
|
|
10
|
-
const app = await build(t);
|
|
11
|
-
const session = { passport: { user: { uid: '1' } } };
|
|
12
|
-
app.decorateRequest('session', session);
|
|
13
|
-
|
|
14
|
-
const prefix = config.prefix || '/api';
|
|
15
|
-
|
|
16
|
-
let addTokens;
|
|
17
|
-
let editTokens;
|
|
18
|
-
|
|
19
|
-
// before
|
|
20
|
-
t.test('setTokenById', async () => {
|
|
21
|
-
addTokens = setTokenById({
|
|
22
|
-
funcs: { config },
|
|
23
|
-
ids: [JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' })],
|
|
24
|
-
mode: 'a',
|
|
25
|
-
session,
|
|
26
|
-
array: 1,
|
|
27
|
-
});
|
|
28
|
-
editTokens = setTokenById({
|
|
29
|
-
funcs: { config },
|
|
30
|
-
ids: [JSON.stringify({ id: '5400000', table: 'gis.dataset', form: 'test.dataset.form' })],
|
|
31
|
-
mode: 'w',
|
|
32
|
-
session,
|
|
33
|
-
array: 1,
|
|
34
|
-
});
|
|
35
|
-
assert.ok(addTokens.length === 1 && editTokens.length === 1, 'invalid token');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
await t.test('POST /insert', async () => {
|
|
39
|
-
const res = await app.inject({
|
|
40
|
-
method: 'POST',
|
|
41
|
-
url: `${prefix}/crud/${addTokens[0]}`,
|
|
42
|
-
body: { dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>', dataset_id: '5400000' },
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const rep = JSON.parse(res?.body);
|
|
46
|
-
|
|
47
|
-
assert.ok(rep.status, 409);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
await t.test('PUT /update', async () => {
|
|
51
|
-
const res = await app.inject({
|
|
52
|
-
method: 'PUT',
|
|
53
|
-
url: `${prefix}/crud/${editTokens[0]}/${editTokens[0]}`,
|
|
54
|
-
body: { editor_id: '11', dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>' },
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const rep = JSON.parse(res?.body);
|
|
58
|
-
|
|
59
|
-
assert.equal(rep.status, 409);
|
|
60
|
-
});
|
|
61
|
-
await t.test('DELETE /delete', async () => {
|
|
62
|
-
const res = await app.inject({
|
|
63
|
-
method: 'DELETE',
|
|
64
|
-
url: `${prefix}/crud/gis.dataset/5400000`,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const rep = JSON.parse(res?.body);
|
|
68
|
-
assert.ok(rep);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../../helper.js';
|
|
5
|
+
|
|
6
|
+
import setTokenById from '../../crud/funcs/setTokenById.js';
|
|
7
|
+
import config from '../config.js';
|
|
8
|
+
|
|
9
|
+
test('api crud xss', async (t) => {
|
|
10
|
+
const app = await build(t);
|
|
11
|
+
const session = { passport: { user: { uid: '1' } } };
|
|
12
|
+
app.decorateRequest('session', session);
|
|
13
|
+
|
|
14
|
+
const prefix = config.prefix || '/api';
|
|
15
|
+
|
|
16
|
+
let addTokens;
|
|
17
|
+
let editTokens;
|
|
18
|
+
|
|
19
|
+
// before
|
|
20
|
+
t.test('setTokenById', async () => {
|
|
21
|
+
addTokens = setTokenById({
|
|
22
|
+
funcs: { config },
|
|
23
|
+
ids: [JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' })],
|
|
24
|
+
mode: 'a',
|
|
25
|
+
session,
|
|
26
|
+
array: 1,
|
|
27
|
+
});
|
|
28
|
+
editTokens = setTokenById({
|
|
29
|
+
funcs: { config },
|
|
30
|
+
ids: [JSON.stringify({ id: '5400000', table: 'gis.dataset', form: 'test.dataset.form' })],
|
|
31
|
+
mode: 'w',
|
|
32
|
+
session,
|
|
33
|
+
array: 1,
|
|
34
|
+
});
|
|
35
|
+
assert.ok(addTokens.length === 1 && editTokens.length === 1, 'invalid token');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await t.test('POST /insert', async () => {
|
|
39
|
+
const res = await app.inject({
|
|
40
|
+
method: 'POST',
|
|
41
|
+
url: `${prefix}/crud/${addTokens[0]}`,
|
|
42
|
+
body: { dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>', dataset_id: '5400000' },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const rep = JSON.parse(res?.body);
|
|
46
|
+
|
|
47
|
+
assert.ok(rep.status, 409);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await t.test('PUT /update', async () => {
|
|
51
|
+
const res = await app.inject({
|
|
52
|
+
method: 'PUT',
|
|
53
|
+
url: `${prefix}/crud/${editTokens[0]}/${editTokens[0]}`,
|
|
54
|
+
body: { editor_id: '11', dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>' },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const rep = JSON.parse(res?.body);
|
|
58
|
+
|
|
59
|
+
assert.equal(rep.status, 409);
|
|
60
|
+
});
|
|
61
|
+
await t.test('DELETE /delete', async () => {
|
|
62
|
+
const res = await app.inject({
|
|
63
|
+
method: 'DELETE',
|
|
64
|
+
url: `${prefix}/crud/gis.dataset/5400000`,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const rep = JSON.parse(res?.body);
|
|
68
|
+
assert.ok(rep);
|
|
69
|
+
});
|
|
70
|
+
});
|
package/test/api/table.test.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
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/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/gis.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 /form', async () => {
|
|
30
|
-
const res = await app.inject({
|
|
31
|
-
method: 'GET',
|
|
32
|
-
url: '/api/form/cp_building.form',
|
|
33
|
-
});
|
|
34
|
-
// console.log(res);
|
|
35
|
-
const rep = JSON.parse(res?.body);
|
|
36
|
-
// console.log(rep.total);
|
|
37
|
-
assert.ok(rep);
|
|
38
|
-
});
|
|
39
|
-
await t.test('GET /filter', async () => {
|
|
40
|
-
const res = await app.inject({
|
|
41
|
-
method: 'GET',
|
|
42
|
-
url: '/api/filter/gis.dataset.table',
|
|
43
|
-
});
|
|
44
|
-
// console.log(res);
|
|
45
|
-
const rep = JSON.parse(res?.body);
|
|
46
|
-
// console.log(rep.total);
|
|
47
|
-
assert.ok(rep);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
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/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/gis.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 /form', async () => {
|
|
30
|
+
const res = await app.inject({
|
|
31
|
+
method: 'GET',
|
|
32
|
+
url: '/api/form/cp_building.form',
|
|
33
|
+
});
|
|
34
|
+
// console.log(res);
|
|
35
|
+
const rep = JSON.parse(res?.body);
|
|
36
|
+
// console.log(rep.total);
|
|
37
|
+
assert.ok(rep);
|
|
38
|
+
});
|
|
39
|
+
await t.test('GET /filter', async () => {
|
|
40
|
+
const res = await app.inject({
|
|
41
|
+
method: 'GET',
|
|
42
|
+
url: '/api/filter/gis.dataset.table',
|
|
43
|
+
});
|
|
44
|
+
// console.log(res);
|
|
45
|
+
const rep = JSON.parse(res?.body);
|
|
46
|
+
// console.log(rep.total);
|
|
47
|
+
assert.ok(rep);
|
|
48
|
+
});
|
|
49
|
+
});
|
package/test/config.example
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import config from '../config.js';
|
|
2
|
-
|
|
3
|
-
Object.assign(config, {
|
|
4
|
-
templateDir: 'test/templates',
|
|
5
|
-
pg: {
|
|
6
|
-
host: '192.168.3.160',
|
|
7
|
-
port: 5434,
|
|
8
|
-
database: 'mbk_rivne_dma',
|
|
9
|
-
user: 'postgres',
|
|
10
|
-
password: 'postgres',
|
|
11
|
-
},
|
|
12
|
-
redis: {
|
|
13
|
-
host: '192.168.3.160',
|
|
14
|
-
port: 6379,
|
|
15
|
-
family: 4,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
export default config;
|
|
1
|
+
import config from '../config.js';
|
|
2
|
+
|
|
3
|
+
Object.assign(config, {
|
|
4
|
+
templateDir: 'test/templates',
|
|
5
|
+
pg: {
|
|
6
|
+
host: '192.168.3.160',
|
|
7
|
+
port: 5434,
|
|
8
|
+
database: 'mbk_rivne_dma',
|
|
9
|
+
user: 'postgres',
|
|
10
|
+
password: 'postgres',
|
|
11
|
+
},
|
|
12
|
+
redis: {
|
|
13
|
+
host: '192.168.3.160',
|
|
14
|
+
port: 6379,
|
|
15
|
+
family: 4,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
export default config;
|
package/test/funcs/crud.test.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
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 isFileExists from '../../crud/funcs/isFileExists.js';
|
|
11
|
-
|
|
12
|
-
import getOpt from '../../crud/funcs/getOpt.js';
|
|
13
|
-
import setOpt from '../../crud/funcs/setOpt.js';
|
|
14
|
-
|
|
15
|
-
import getIdByToken from '../../crud/funcs/getIdByToken.js';
|
|
16
|
-
import setTokenById from '../../crud/funcs/setTokenById.js';
|
|
17
|
-
import config from '../config.js';
|
|
18
|
-
|
|
19
|
-
test('funcs crud', async (t) => {
|
|
20
|
-
await t.test('getOpt/setOpt', async () => {
|
|
21
|
-
const opt = await setOpt({ table: 'gis.dataset' });
|
|
22
|
-
const data = await getOpt(opt);
|
|
23
|
-
// console.log(data);
|
|
24
|
-
assert.equal(data.table, 'gis.dataset');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const id = (Math.random() * 10000).toFixed();
|
|
28
|
-
await t.test('dataInsert', async () => {
|
|
29
|
-
const data = await dataInsert({ table: 'gis.dataset', data: { dataset_id: id, dataset_name: '222' } });
|
|
30
|
-
assert.equal(data.dataset_id, id);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
await t.test('dataUpdate', async () => {
|
|
34
|
-
const data = await dataUpdate({ table: 'gis.dataset', id, data: { dataset_name: '22211' } });
|
|
35
|
-
assert.equal(data.dataset_name, '22211');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
await t.test('dataDelete', async () => {
|
|
39
|
-
const data = await dataDelete({ table: 'gis.dataset', id });
|
|
40
|
-
assert.ok(data);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
await t.test('isFileExists', async () => {
|
|
44
|
-
const data = await isFileExists({ filepath: '../../crud/funcs/isFileExists.js' });
|
|
45
|
-
assert.equal(data, false);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
let tokens;
|
|
49
|
-
const session = { passport: { user: { uid: '1' } } };
|
|
50
|
-
const tokenData = JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' });
|
|
51
|
-
|
|
52
|
-
await t.test('setTokenById', async () => {
|
|
53
|
-
tokens = setTokenById({
|
|
54
|
-
funcs: { config },
|
|
55
|
-
ids: [tokenData],
|
|
56
|
-
mode: 'a',
|
|
57
|
-
session,
|
|
58
|
-
array: 1,
|
|
59
|
-
});
|
|
60
|
-
assert.equal(tokens.length, 1);
|
|
61
|
-
});
|
|
62
|
-
await t.test('getIdByToken', async () => {
|
|
63
|
-
const data = await getIdByToken({
|
|
64
|
-
funcs: { config },
|
|
65
|
-
session,
|
|
66
|
-
token: tokens[0],
|
|
67
|
-
mode: 'a',
|
|
68
|
-
});
|
|
69
|
-
assert.equal(data, tokenData);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// pgClients.client.query('delete from gis.dataset where dataset_id=$1', [id]);
|
|
73
|
-
t.after(() => {
|
|
74
|
-
pgClients.client?.end();
|
|
75
|
-
rclient.quit();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
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 isFileExists from '../../crud/funcs/isFileExists.js';
|
|
11
|
+
|
|
12
|
+
import getOpt from '../../crud/funcs/getOpt.js';
|
|
13
|
+
import setOpt from '../../crud/funcs/setOpt.js';
|
|
14
|
+
|
|
15
|
+
import getIdByToken from '../../crud/funcs/getIdByToken.js';
|
|
16
|
+
import setTokenById from '../../crud/funcs/setTokenById.js';
|
|
17
|
+
import config from '../config.js';
|
|
18
|
+
|
|
19
|
+
test('funcs crud', async (t) => {
|
|
20
|
+
await t.test('getOpt/setOpt', async () => {
|
|
21
|
+
const opt = await setOpt({ table: 'gis.dataset' });
|
|
22
|
+
const data = await getOpt(opt);
|
|
23
|
+
// console.log(data);
|
|
24
|
+
assert.equal(data.table, 'gis.dataset');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const id = (Math.random() * 10000).toFixed();
|
|
28
|
+
await t.test('dataInsert', async () => {
|
|
29
|
+
const data = await dataInsert({ table: 'gis.dataset', data: { dataset_id: id, dataset_name: '222' } });
|
|
30
|
+
assert.equal(data.dataset_id, id);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await t.test('dataUpdate', async () => {
|
|
34
|
+
const data = await dataUpdate({ table: 'gis.dataset', id, data: { dataset_name: '22211' } });
|
|
35
|
+
assert.equal(data.dataset_name, '22211');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await t.test('dataDelete', async () => {
|
|
39
|
+
const data = await dataDelete({ table: 'gis.dataset', id });
|
|
40
|
+
assert.ok(data);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
await t.test('isFileExists', async () => {
|
|
44
|
+
const data = await isFileExists({ filepath: '../../crud/funcs/isFileExists.js' });
|
|
45
|
+
assert.equal(data, false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
let tokens;
|
|
49
|
+
const session = { passport: { user: { uid: '1' } } };
|
|
50
|
+
const tokenData = JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' });
|
|
51
|
+
|
|
52
|
+
await t.test('setTokenById', async () => {
|
|
53
|
+
tokens = setTokenById({
|
|
54
|
+
funcs: { config },
|
|
55
|
+
ids: [tokenData],
|
|
56
|
+
mode: 'a',
|
|
57
|
+
session,
|
|
58
|
+
array: 1,
|
|
59
|
+
});
|
|
60
|
+
assert.equal(tokens.length, 1);
|
|
61
|
+
});
|
|
62
|
+
await t.test('getIdByToken', async () => {
|
|
63
|
+
const data = await getIdByToken({
|
|
64
|
+
funcs: { config },
|
|
65
|
+
session,
|
|
66
|
+
token: tokens[0],
|
|
67
|
+
mode: 'a',
|
|
68
|
+
});
|
|
69
|
+
assert.equal(data, tokenData);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// pgClients.client.query('delete from gis.dataset where dataset_id=$1', [id]);
|
|
73
|
+
t.after(() => {
|
|
74
|
+
pgClients.client?.end();
|
|
75
|
+
rclient.quit();
|
|
76
|
+
});
|
|
77
|
+
});
|