@opengis/fastify-table 1.3.20 → 1.3.21
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/README.md +86 -86
- package/package.json +1 -1
- package/server/plugins/cron/funcs/addCron.js +52 -52
- package/server/plugins/cron/index.js +74 -74
- package/server/plugins/crud/funcs/getOpt.js +13 -13
- package/server/plugins/crud/funcs/setOpt.js +21 -21
- package/server/plugins/crud/funcs/setToken.js +44 -44
- package/server/plugins/crud/funcs/utils/getFolder.js +11 -11
- package/server/plugins/crud/index.js +23 -23
- package/server/plugins/hook/index.js +8 -8
- package/server/plugins/logger/errorStatus.js +19 -19
- package/server/plugins/logger/index.js +26 -26
- package/server/plugins/migration/index.js +7 -7
- package/server/plugins/policy/sqlInjection.js +33 -33
- package/server/plugins/redis/client.js +8 -8
- package/server/plugins/redis/funcs/redisClients.js +3 -3
- package/server/plugins/redis/index.js +17 -17
- package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/server/plugins/table/funcs/getTemplates.js +19 -19
- package/server/plugins/table/funcs/gisIRColumn.js +82 -82
- package/server/plugins/table/funcs/loadTemplate.js +1 -1
- package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
- package/server/plugins/table/funcs/userTemplateDir.js +1 -1
- package/server/plugins/table/index.js +13 -13
- package/server/plugins/util/index.js +7 -7
- package/server/routes/cron/index.js +14 -14
- package/server/routes/logger/controllers/logger.file.js +92 -92
- package/server/routes/logger/controllers/utils/checkUserAccess.js +19 -19
- package/server/routes/logger/controllers/utils/getRootDir.js +26 -26
- package/server/routes/logger/index.js +17 -17
- package/server/routes/properties/controllers/properties.add.js +55 -55
- package/server/routes/properties/controllers/properties.get.js +17 -17
- package/server/routes/properties/index.js +16 -16
- package/server/routes/table/controllers/filter.js +1 -1
- package/server/routes/table/controllers/form.js +42 -42
- package/server/routes/table/controllers/search.js +74 -74
- package/server/routes/table/schema.js +64 -64
- package/server/routes/util/controllers/status.monitor.js +8 -8
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
// import getOpt from './funcs/getOpt.js';
|
|
2
|
-
// import setOpt from './funcs/setOpt.js';
|
|
3
|
-
|
|
4
|
-
// import isFileExists from './funcs/isFileExists.js';
|
|
5
|
-
|
|
6
|
-
// import dataUpdate from './funcs/dataUpdate.js';
|
|
7
|
-
// import dataInsert from './funcs/dataInsert.js';
|
|
8
|
-
|
|
9
|
-
// import getAccessFunc from './funcs/getAccess.js';
|
|
10
|
-
|
|
11
|
-
async function plugin(fastify) {
|
|
12
|
-
// fastify.decorate('setOpt', setOpt);
|
|
13
|
-
// fastify.decorate('getOpt', getOpt);
|
|
14
|
-
|
|
15
|
-
// fastify.decorate('dataUpdate', dataUpdate);
|
|
16
|
-
// fastify.decorate('dataInsert', dataInsert);
|
|
17
|
-
|
|
18
|
-
// fastify.decorate('getAccess', getAccessFunc);
|
|
19
|
-
|
|
20
|
-
// fastify.decorate('isFileExists', isFileExists);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default plugin;
|
|
1
|
+
// import getOpt from './funcs/getOpt.js';
|
|
2
|
+
// import setOpt from './funcs/setOpt.js';
|
|
3
|
+
|
|
4
|
+
// import isFileExists from './funcs/isFileExists.js';
|
|
5
|
+
|
|
6
|
+
// import dataUpdate from './funcs/dataUpdate.js';
|
|
7
|
+
// import dataInsert from './funcs/dataInsert.js';
|
|
8
|
+
|
|
9
|
+
// import getAccessFunc from './funcs/getAccess.js';
|
|
10
|
+
|
|
11
|
+
async function plugin(fastify) {
|
|
12
|
+
// fastify.decorate('setOpt', setOpt);
|
|
13
|
+
// fastify.decorate('getOpt', getOpt);
|
|
14
|
+
|
|
15
|
+
// fastify.decorate('dataUpdate', dataUpdate);
|
|
16
|
+
// fastify.decorate('dataInsert', dataInsert);
|
|
17
|
+
|
|
18
|
+
// fastify.decorate('getAccess', getAccessFunc);
|
|
19
|
+
|
|
20
|
+
// fastify.decorate('isFileExists', isFileExists);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default plugin;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import addHook from './funcs/addHook.js';
|
|
2
|
-
import applyHook from './funcs/applyHook.js';
|
|
3
|
-
|
|
4
|
-
async function plugin(fastify) {
|
|
5
|
-
// fastify.decorate('addHook', addHook);
|
|
6
|
-
// fastify.decorate('applyHook', applyHook);
|
|
7
|
-
}
|
|
8
|
-
export default plugin;
|
|
1
|
+
import addHook from './funcs/addHook.js';
|
|
2
|
+
import applyHook from './funcs/applyHook.js';
|
|
3
|
+
|
|
4
|
+
async function plugin(fastify) {
|
|
5
|
+
// fastify.decorate('addHook', addHook);
|
|
6
|
+
// fastify.decorate('applyHook', applyHook);
|
|
7
|
+
}
|
|
8
|
+
export default plugin;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import applyHookSync from '../hook/funcs/applyHookSync.js';
|
|
2
|
-
|
|
3
|
-
function errorStatus(error) {
|
|
4
|
-
const hook = applyHookSync('errorStatus', error);
|
|
5
|
-
if (hook) return hook;
|
|
6
|
-
|
|
7
|
-
if (error.routine === 'exec_stmt_raise' && error.file === 'pl_exec.c') {
|
|
8
|
-
return 601;
|
|
9
|
-
}
|
|
10
|
-
if (error.routine === 'ExecConstraints') {
|
|
11
|
-
return 602;
|
|
12
|
-
}
|
|
13
|
-
if (error.type === 'DatabaseError') {
|
|
14
|
-
return 600;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return 500;
|
|
18
|
-
}
|
|
19
|
-
export default errorStatus;
|
|
1
|
+
import applyHookSync from '../hook/funcs/applyHookSync.js';
|
|
2
|
+
|
|
3
|
+
function errorStatus(error) {
|
|
4
|
+
const hook = applyHookSync('errorStatus', error);
|
|
5
|
+
if (hook) return hook;
|
|
6
|
+
|
|
7
|
+
if (error.routine === 'exec_stmt_raise' && error.file === 'pl_exec.c') {
|
|
8
|
+
return 601;
|
|
9
|
+
}
|
|
10
|
+
if (error.routine === 'ExecConstraints') {
|
|
11
|
+
return 602;
|
|
12
|
+
}
|
|
13
|
+
if (error.type === 'DatabaseError') {
|
|
14
|
+
return 600;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return 500;
|
|
18
|
+
}
|
|
19
|
+
export default errorStatus;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import errorMessage from './errorMessage.js';
|
|
2
|
-
import logger from './getLogger.js';
|
|
3
|
-
import pgClients from '../pg/pgClients.js';
|
|
4
|
-
|
|
5
|
-
async function plugin(fastify) {
|
|
6
|
-
fastify.setErrorHandler(async (error, request, reply) => {
|
|
7
|
-
// validation not error
|
|
8
|
-
if (error.validation) {
|
|
9
|
-
request.log.warn(request, { code: error?.code, status: 422, error: error.toString() });
|
|
10
|
-
return reply.status(422).send(error.toString());
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// logger
|
|
14
|
-
request.log.error(error, request);
|
|
15
|
-
console.error({ msg: error.message, where: error.where, stack: error.stack });
|
|
16
|
-
|
|
17
|
-
// errorMessage
|
|
18
|
-
const msg = errorMessage(error);
|
|
19
|
-
|
|
20
|
-
return reply.status(error.statusCode || 500).send(msg);
|
|
21
|
-
});
|
|
22
|
-
fastify.addHook('onListen', async () => {
|
|
23
|
-
logger.file('init', { db: pgClients.client?.options?.database });
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export default plugin;
|
|
1
|
+
import errorMessage from './errorMessage.js';
|
|
2
|
+
import logger from './getLogger.js';
|
|
3
|
+
import pgClients from '../pg/pgClients.js';
|
|
4
|
+
|
|
5
|
+
async function plugin(fastify) {
|
|
6
|
+
fastify.setErrorHandler(async (error, request, reply) => {
|
|
7
|
+
// validation not error
|
|
8
|
+
if (error.validation) {
|
|
9
|
+
request.log.warn(request, { code: error?.code, status: 422, error: error.toString() });
|
|
10
|
+
return reply.status(422).send(error.toString());
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// logger
|
|
14
|
+
request.log.error(error, request);
|
|
15
|
+
console.error({ msg: error.message, where: error.where, stack: error.stack });
|
|
16
|
+
|
|
17
|
+
// errorMessage
|
|
18
|
+
const msg = errorMessage(error);
|
|
19
|
+
|
|
20
|
+
return reply.status(error.statusCode || 500).send(msg);
|
|
21
|
+
});
|
|
22
|
+
fastify.addHook('onListen', async () => {
|
|
23
|
+
logger.file('init', { db: pgClients.client?.options?.database });
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export default plugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import execMigrations from './funcs/exec.migrations.js';
|
|
2
|
-
|
|
3
|
-
async function plugin(fastify) {
|
|
4
|
-
// fastify.decorate('execMigrations', execMigrations);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default plugin;
|
|
1
|
+
import execMigrations from './funcs/exec.migrations.js';
|
|
2
|
+
|
|
3
|
+
async function plugin(fastify) {
|
|
4
|
+
// fastify.decorate('execMigrations', execMigrations);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default plugin;
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
const sqlInjection = [
|
|
2
|
-
'()',
|
|
3
|
-
'^',
|
|
4
|
-
'*',
|
|
5
|
-
'like ',
|
|
6
|
-
'@variable',
|
|
7
|
-
'@@variable',
|
|
8
|
-
'group by ',
|
|
9
|
-
'union ',
|
|
10
|
-
'select ',
|
|
11
|
-
'having ',
|
|
12
|
-
'as injectx',
|
|
13
|
-
'where ',
|
|
14
|
-
'rlike ',
|
|
15
|
-
'if(',
|
|
16
|
-
'sleep(',
|
|
17
|
-
'waitfor delay',
|
|
18
|
-
'benchmark(',
|
|
19
|
-
'pg_sleep(',
|
|
20
|
-
"'\\\"",
|
|
21
|
-
'randomblob(',
|
|
22
|
-
'order by ',
|
|
23
|
-
'union all ',
|
|
24
|
-
'+or',
|
|
25
|
-
'or ',
|
|
26
|
-
'and ',
|
|
27
|
-
"'' ",
|
|
28
|
-
'""" ',
|
|
29
|
-
'<script',
|
|
30
|
-
'javascript:',
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
export default sqlInjection;
|
|
1
|
+
const sqlInjection = [
|
|
2
|
+
'()',
|
|
3
|
+
'^',
|
|
4
|
+
'*',
|
|
5
|
+
'like ',
|
|
6
|
+
'@variable',
|
|
7
|
+
'@@variable',
|
|
8
|
+
'group by ',
|
|
9
|
+
'union ',
|
|
10
|
+
'select ',
|
|
11
|
+
'having ',
|
|
12
|
+
'as injectx',
|
|
13
|
+
'where ',
|
|
14
|
+
'rlike ',
|
|
15
|
+
'if(',
|
|
16
|
+
'sleep(',
|
|
17
|
+
'waitfor delay',
|
|
18
|
+
'benchmark(',
|
|
19
|
+
'pg_sleep(',
|
|
20
|
+
"'\\\"",
|
|
21
|
+
'randomblob(',
|
|
22
|
+
'order by ',
|
|
23
|
+
'union all ',
|
|
24
|
+
'+or',
|
|
25
|
+
'or ',
|
|
26
|
+
'and ',
|
|
27
|
+
"'' ",
|
|
28
|
+
'""" ',
|
|
29
|
+
'<script',
|
|
30
|
+
'javascript:',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
export default sqlInjection;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import redisClients from './funcs/redisClients.js';
|
|
2
|
-
import getRedis from './funcs/getRedis.js';
|
|
3
|
-
|
|
4
|
-
if (!redisClients[0]) {
|
|
5
|
-
getRedis({ db: 0 });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default redisClients[0];
|
|
1
|
+
import redisClients from './funcs/redisClients.js';
|
|
2
|
+
import getRedis from './funcs/getRedis.js';
|
|
3
|
+
|
|
4
|
+
if (!redisClients[0]) {
|
|
5
|
+
getRedis({ db: 0 });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default redisClients[0];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const redisClients = {};
|
|
2
|
-
|
|
3
|
-
export default redisClients;
|
|
1
|
+
const redisClients = {};
|
|
2
|
+
|
|
3
|
+
export default redisClients;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// import redis from './client.js';
|
|
2
|
-
import redisClients from './funcs/redisClients.js';
|
|
3
|
-
|
|
4
|
-
function close(fastify) {
|
|
5
|
-
// redis.quit();
|
|
6
|
-
Object.keys(redisClients).forEach((key) => redisClients[key].quit());
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async function plugin(fastify) {
|
|
10
|
-
// const client = getRedis({ db: 0 });
|
|
11
|
-
// client.getJSON = client.get;
|
|
12
|
-
// fastify.decorate('rclient', client);
|
|
13
|
-
// fastify.decorate('getRedis', getRedis);
|
|
14
|
-
fastify.addHook('onClose', close);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default plugin;
|
|
1
|
+
// import redis from './client.js';
|
|
2
|
+
import redisClients from './funcs/redisClients.js';
|
|
3
|
+
|
|
4
|
+
function close(fastify) {
|
|
5
|
+
// redis.quit();
|
|
6
|
+
Object.keys(redisClients).forEach((key) => redisClients[key].quit());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async function plugin(fastify) {
|
|
10
|
+
// const client = getRedis({ db: 0 });
|
|
11
|
+
// client.getJSON = client.get;
|
|
12
|
+
// fastify.decorate('rclient', client);
|
|
13
|
+
// fastify.decorate('getRedis', getRedis);
|
|
14
|
+
fastify.addHook('onClose', close);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default plugin;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
async function getCustomQuery({
|
|
2
|
-
pg, table, customFilter,
|
|
3
|
-
}) {
|
|
4
|
-
if (!customFilter) return null;
|
|
5
|
-
const customFilterList = customFilter?.split(',')?.map((el) => el?.split('_').pop());
|
|
6
|
-
const { property_json: customFilterSQL } = await pg.one(`select json_agg(json_build_object('id',property_id,'name',property_key,'query',property_text)
|
|
7
|
-
) as property_json from admin.properties where property_key is not null and property_entity='customQuery' and object_id=$1`, [table]);
|
|
8
|
-
const data = customFilterSQL?.length ? customFilterSQL.filter((el) => customFilterList.includes(el.id)) || [] : [];
|
|
9
|
-
const customQuery = data?.map((el) => el.query).join(' and ');
|
|
10
|
-
return `${customQuery}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default getCustomQuery;
|
|
1
|
+
async function getCustomQuery({
|
|
2
|
+
pg, table, customFilter,
|
|
3
|
+
}) {
|
|
4
|
+
if (!customFilter) return null;
|
|
5
|
+
const customFilterList = customFilter?.split(',')?.map((el) => el?.split('_').pop());
|
|
6
|
+
const { property_json: customFilterSQL } = await pg.one(`select json_agg(json_build_object('id',property_id,'name',property_key,'query',property_text)
|
|
7
|
+
) as property_json from admin.properties where property_key is not null and property_entity='customQuery' and object_id=$1`, [table]);
|
|
8
|
+
const data = customFilterSQL?.length ? customFilterSQL.filter((el) => customFilterList.includes(el.id)) || [] : [];
|
|
9
|
+
const customQuery = data?.map((el) => el.query).join(' and ');
|
|
10
|
+
return `${customQuery}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default getCustomQuery;
|
|
@@ -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`);
|
|
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`);
|
|
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,19 +1,19 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import config from '../../../../config.js';
|
|
5
|
-
|
|
6
|
-
const loadTemplate = {};
|
|
7
|
-
|
|
8
|
-
export default async function getTemplateDir(type) {
|
|
9
|
-
if (!type) return null;
|
|
10
|
-
|
|
11
|
-
const cwd = process.cwd();
|
|
12
|
-
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
13
|
-
|
|
14
|
-
if (!loadTemplate[type]) {
|
|
15
|
-
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
16
|
-
loadTemplate[type] = typeList;
|
|
17
|
-
}
|
|
18
|
-
return loadTemplate[type];
|
|
19
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import config from '../../../../config.js';
|
|
5
|
+
|
|
6
|
+
const loadTemplate = {};
|
|
7
|
+
|
|
8
|
+
export default async function getTemplateDir(type) {
|
|
9
|
+
if (!type) return null;
|
|
10
|
+
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
13
|
+
|
|
14
|
+
if (!loadTemplate[type]) {
|
|
15
|
+
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
16
|
+
loadTemplate[type] = typeList;
|
|
17
|
+
}
|
|
18
|
+
return loadTemplate[type];
|
|
19
|
+
}
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import getSelect from './getSelect.js';
|
|
2
|
-
|
|
3
|
-
import getFilterSQL from './getFilterSQL/index.js';
|
|
4
|
-
import getTemplate from './getTemplate.js';
|
|
5
|
-
import pgClients from '../../pg/pgClients.js';
|
|
6
|
-
import config from '../../../../config.js';
|
|
7
|
-
import getSelectVal from './metaFormat/getSelectVal.js';
|
|
8
|
-
|
|
9
|
-
export default async function gisIRColumn({
|
|
10
|
-
pg = pgClients.client, layer, column, sql, query = '1=1', filter, state, search, custom,
|
|
11
|
-
}) {
|
|
12
|
-
const time = Date.now();
|
|
13
|
-
|
|
14
|
-
const sel = await getSelect(query.cls || column, pg);
|
|
15
|
-
|
|
16
|
-
const body = await getTemplate('table', layer);
|
|
17
|
-
const fData = await getFilterSQL({
|
|
18
|
-
table: layer,
|
|
19
|
-
filter,
|
|
20
|
-
state,
|
|
21
|
-
search,
|
|
22
|
-
custom,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const { tlist } = await pg.one(`select array_agg((select nspname from pg_namespace where oid=relnamespace)||'.'||relname) tlist from pg_class
|
|
26
|
-
where relkind in ('r','v','m')`);
|
|
27
|
-
|
|
28
|
-
const tableName = body?.table || layer;
|
|
29
|
-
if (!tlist.includes(tableName)) return { error: `table not found: ${tableName}`, status: 400 };
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line max-len
|
|
32
|
-
const { fields } = await pg.query(`select * from (${fData?.optimizedSQL || `select * from ${tableName}`})q limit 0`);
|
|
33
|
-
|
|
34
|
-
const col = fields.find((el) => el.name === column);
|
|
35
|
-
|
|
36
|
-
if (!col) return { status: 404, message: 'not found' };
|
|
37
|
-
const colField = pg.pgType[col.dataTypeID]?.includes('[]') ? `unnest(${column})` : column;
|
|
38
|
-
|
|
39
|
-
const q = `select ${colField} as id, count(*)::int from (
|
|
40
|
-
${fData?.optimizedSQL || `select * from ${tableName} where ${body?.query || 'true'}`}
|
|
41
|
-
)t group by ${colField} order by count desc limit 15`;
|
|
42
|
-
|
|
43
|
-
if (sql) return q;
|
|
44
|
-
|
|
45
|
-
if (!body?.columns?.length) {
|
|
46
|
-
const { rows } = await pg.query(q);
|
|
47
|
-
if (sel?.arr?.length) {
|
|
48
|
-
rows.forEach((el) => {
|
|
49
|
-
const data = sel?.find((item) => item.id?.toString() === el.id?.toString());
|
|
50
|
-
Object.assign(el, data || {});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
count: rows?.reduce((acc, el) => acc + el.count, 0),
|
|
55
|
-
sql: config.local ? q : undefined,
|
|
56
|
-
rows,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const { rows } = await pg.query(q);
|
|
61
|
-
const cls = query.cls || body?.columns?.find((el) => el.name === column)?.data || col.data || col.option;
|
|
62
|
-
const select = await getSelectVal({
|
|
63
|
-
pg, name: cls, values: rows.map((el) => el.id), ar: 1,
|
|
64
|
-
});
|
|
65
|
-
rows.forEach((el) => {
|
|
66
|
-
if (Array.isArray(select)) {
|
|
67
|
-
Object.assign(el, select.find((item) => item.id?.toString() === el.id?.toString()) || {});
|
|
68
|
-
}
|
|
69
|
-
else if (typeof select?.[el.id] === 'string') {
|
|
70
|
-
Object.assign(el, { text: select?.[el.id] });
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
Object.assign(el, select?.[el.id] || {});
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
return {
|
|
77
|
-
time: Date.now() - time,
|
|
78
|
-
count: rows.reduce((acc, el) => acc + el.count, 0),
|
|
79
|
-
sql: config.local ? q : undefined,
|
|
80
|
-
rows,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
1
|
+
import getSelect from './getSelect.js';
|
|
2
|
+
|
|
3
|
+
import getFilterSQL from './getFilterSQL/index.js';
|
|
4
|
+
import getTemplate from './getTemplate.js';
|
|
5
|
+
import pgClients from '../../pg/pgClients.js';
|
|
6
|
+
import config from '../../../../config.js';
|
|
7
|
+
import getSelectVal from './metaFormat/getSelectVal.js';
|
|
8
|
+
|
|
9
|
+
export default async function gisIRColumn({
|
|
10
|
+
pg = pgClients.client, layer, column, sql, query = '1=1', filter, state, search, custom,
|
|
11
|
+
}) {
|
|
12
|
+
const time = Date.now();
|
|
13
|
+
|
|
14
|
+
const sel = await getSelect(query.cls || column, pg);
|
|
15
|
+
|
|
16
|
+
const body = await getTemplate('table', layer);
|
|
17
|
+
const fData = await getFilterSQL({
|
|
18
|
+
table: layer,
|
|
19
|
+
filter,
|
|
20
|
+
state,
|
|
21
|
+
search,
|
|
22
|
+
custom,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const { tlist } = await pg.one(`select array_agg((select nspname from pg_namespace where oid=relnamespace)||'.'||relname) tlist from pg_class
|
|
26
|
+
where relkind in ('r','v','m')`);
|
|
27
|
+
|
|
28
|
+
const tableName = body?.table || layer;
|
|
29
|
+
if (!tlist.includes(tableName)) return { error: `table not found: ${tableName}`, status: 400 };
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line max-len
|
|
32
|
+
const { fields } = await pg.query(`select * from (${fData?.optimizedSQL || `select * from ${tableName}`})q limit 0`);
|
|
33
|
+
|
|
34
|
+
const col = fields.find((el) => el.name === column);
|
|
35
|
+
|
|
36
|
+
if (!col) return { status: 404, message: 'not found' };
|
|
37
|
+
const colField = pg.pgType[col.dataTypeID]?.includes('[]') ? `unnest(${column})` : column;
|
|
38
|
+
|
|
39
|
+
const q = `select ${colField} as id, count(*)::int from (
|
|
40
|
+
${fData?.optimizedSQL || `select * from ${tableName} where ${body?.query || 'true'}`}
|
|
41
|
+
)t group by ${colField} order by count desc limit 15`;
|
|
42
|
+
|
|
43
|
+
if (sql) return q;
|
|
44
|
+
|
|
45
|
+
if (!body?.columns?.length) {
|
|
46
|
+
const { rows } = await pg.query(q);
|
|
47
|
+
if (sel?.arr?.length) {
|
|
48
|
+
rows.forEach((el) => {
|
|
49
|
+
const data = sel?.find((item) => item.id?.toString() === el.id?.toString());
|
|
50
|
+
Object.assign(el, data || {});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
count: rows?.reduce((acc, el) => acc + el.count, 0),
|
|
55
|
+
sql: config.local ? q : undefined,
|
|
56
|
+
rows,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const { rows } = await pg.query(q);
|
|
61
|
+
const cls = query.cls || body?.columns?.find((el) => el.name === column)?.data || col.data || col.option;
|
|
62
|
+
const select = await getSelectVal({
|
|
63
|
+
pg, name: cls, values: rows.map((el) => el.id), ar: 1,
|
|
64
|
+
});
|
|
65
|
+
rows.forEach((el) => {
|
|
66
|
+
if (Array.isArray(select)) {
|
|
67
|
+
Object.assign(el, select.find((item) => item.id?.toString() === el.id?.toString()) || {});
|
|
68
|
+
}
|
|
69
|
+
else if (typeof select?.[el.id] === 'string') {
|
|
70
|
+
Object.assign(el, { text: select?.[el.id] });
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
Object.assign(el, select?.[el.id] || {});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
time: Date.now() - time,
|
|
78
|
+
count: rows.reduce((acc, el) => acc + el.count, 0),
|
|
79
|
+
sql: config.local ? q : undefined,
|
|
80
|
+
rows,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default {};
|
|
1
|
+
export default {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default {};
|
|
1
|
+
export default {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default [];
|
|
1
|
+
export default [];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import metaFormat from './funcs/metaFormat/index.js';
|
|
2
|
-
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
3
|
-
import getTemplate from './funcs/getTemplate.js';
|
|
4
|
-
import getSelect from './funcs/getSelect.js';
|
|
5
|
-
|
|
6
|
-
async function plugin(fastify) {
|
|
7
|
-
// fastify.decorate('metaFormat', metaFormat);
|
|
8
|
-
// fastify.decorate('getFilterSQL', getFilterSQL);
|
|
9
|
-
// fastify.decorate('getTemplate', getTemplate);
|
|
10
|
-
// fastify.decorate('getSelect', getSelect);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default plugin;
|
|
1
|
+
import metaFormat from './funcs/metaFormat/index.js';
|
|
2
|
+
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
3
|
+
import getTemplate from './funcs/getTemplate.js';
|
|
4
|
+
import getSelect from './funcs/getSelect.js';
|
|
5
|
+
|
|
6
|
+
async function plugin(fastify) {
|
|
7
|
+
// fastify.decorate('metaFormat', metaFormat);
|
|
8
|
+
// fastify.decorate('getFilterSQL', getFilterSQL);
|
|
9
|
+
// fastify.decorate('getTemplate', getTemplate);
|
|
10
|
+
// fastify.decorate('getSelect', getSelect);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default plugin;
|