@opengis/fastify-table 1.0.9 → 1.0.11
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/dataUpdate.js +3 -3
- package/crud/funcs/{getIdByToken.js → getToken.js} +27 -29
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/{setTokenById.js → setToken.js} +53 -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/getPG.js +3 -0
- package/pg/funcs/init.js +42 -42
- package/pg/funcs/pgClients.js +2 -2
- package/pg/index.js +35 -35
- package/pg/pgClients.js +20 -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/getRedis.js +1 -2
- 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/getSelectVal.js +20 -0
- package/table/funcs/metaFormat/index.js +24 -0
- package/table/index.js +25 -14
- package/test/api/crud.test.js +50 -50
- package/test/api/crud.xss.test.js +68 -70
- package/test/api/table.test.js +49 -49
- package/test/config.example +18 -18
- package/test/funcs/crud.test.js +76 -77
- package/test/funcs/pg.test.js +34 -32
- package/test/funcs/redis.test.js +19 -19
- 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
- package/test/funcs/table.test.js +0 -48
|
@@ -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,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.text }), {}) };
|
|
16
|
+
if (!cls.arr && data.length) {
|
|
17
|
+
redis.hmset(key, clsAr);
|
|
18
|
+
}
|
|
19
|
+
return clsAr;
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import getTemplate from '../../controllers/utils/getTemplate.js';
|
|
2
|
+
import getSelectVal from './getSelectVal.js';
|
|
3
|
+
|
|
4
|
+
export default async function metaFormat({ rows, table }) {
|
|
5
|
+
const loadTable = await getTemplate('table', table);
|
|
6
|
+
const selectCols = loadTable.columns?.filter((e) => e.data);
|
|
7
|
+
|
|
8
|
+
// cls & select format
|
|
9
|
+
|
|
10
|
+
await Promise.all(selectCols?.map(async (attr) => {
|
|
11
|
+
const val = [...new Set(rows?.map((el) => el[attr.name]).flat())].filter((el) => el);
|
|
12
|
+
if (!val.length) return null;
|
|
13
|
+
|
|
14
|
+
const clsAr = await getSelectVal({ name: attr.data, values: val });
|
|
15
|
+
if (!clsAr) return null;
|
|
16
|
+
rows.forEach(el => {
|
|
17
|
+
Object.assign(el, { [`${attr.name}_text`]: clsAr[el[attr.name]] || el[attr.name] });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return null;
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
return rows;
|
|
24
|
+
}
|
package/table/index.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
const tableSchema = {
|
|
8
|
+
querystring: {
|
|
9
|
+
page: { type: 'number' },
|
|
10
|
+
order: { type: 'string' },
|
|
11
|
+
filter: { type: 'string' },
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
async function plugin(fastify, config = {}) {
|
|
16
|
+
const prefix = config.prefix || '/api';
|
|
17
|
+
fastify.decorate('metaFormat', metaFormat);
|
|
18
|
+
|
|
19
|
+
fastify.get(`${prefix}/suggest/:data`, {}, suggest);
|
|
20
|
+
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
21
|
+
fastify.get(`${prefix}/filter/:table`, {}, filter);
|
|
22
|
+
fastify.get(`${prefix}/form/:form`, {}, form);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
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,68 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../../helper.js';
|
|
5
|
-
|
|
6
|
-
import
|
|
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('
|
|
21
|
-
addTokens =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../../helper.js';
|
|
5
|
+
|
|
6
|
+
import setToken from '../../crud/funcs/setToken.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('setToken', async () => {
|
|
21
|
+
addTokens = setToken({
|
|
22
|
+
ids: [JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' })],
|
|
23
|
+
mode: 'a',
|
|
24
|
+
uid: 1,
|
|
25
|
+
array: 1,
|
|
26
|
+
});
|
|
27
|
+
editTokens = setToken({
|
|
28
|
+
ids: [JSON.stringify({ id: '5400000', table: 'gis.dataset', form: 'test.dataset.form' })],
|
|
29
|
+
mode: 'w',
|
|
30
|
+
uid: 1,
|
|
31
|
+
array: 1,
|
|
32
|
+
});
|
|
33
|
+
assert.ok(addTokens.length === 1 && editTokens.length === 1, 'invalid token');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await t.test('POST /insert', async () => {
|
|
37
|
+
const res = await app.inject({
|
|
38
|
+
method: 'POST',
|
|
39
|
+
url: `${prefix}/crud/${addTokens[0]}`,
|
|
40
|
+
body: { dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>', dataset_id: '5400000' },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const rep = JSON.parse(res?.body);
|
|
44
|
+
|
|
45
|
+
assert.ok(rep.status, 409);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await t.test('PUT /update', async () => {
|
|
49
|
+
const res = await app.inject({
|
|
50
|
+
method: 'PUT',
|
|
51
|
+
url: `${prefix}/crud/${editTokens[0]}/${editTokens[0]}`,
|
|
52
|
+
body: { editor_id: '11', dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>' },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const rep = JSON.parse(res?.body);
|
|
56
|
+
|
|
57
|
+
assert.equal(rep.status, 409);
|
|
58
|
+
});
|
|
59
|
+
await t.test('DELETE /delete', async () => {
|
|
60
|
+
const res = await app.inject({
|
|
61
|
+
method: 'DELETE',
|
|
62
|
+
url: `${prefix}/crud/gis.dataset/5400000`,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const rep = JSON.parse(res?.body);
|
|
66
|
+
assert.ok(rep);
|
|
67
|
+
});
|
|
68
|
+
});
|
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;
|