@opengis/admin 0.2.104 → 0.2.105
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
import getData from '@opengis/fastify-table/server/routes/table/controllers/data.js';
|
2
|
-
import { getOpt } from '@opengis/fastify-table/utils.js';
|
2
|
+
import { getOpt, getMeta } from '@opengis/fastify-table/utils.js';
|
3
3
|
// import getData from '../../../../../../npm/fastify-table/server/routes/table/controllers/data.js';
|
4
4
|
|
5
5
|
export default async function getTableData(req) {
|
6
6
|
const { user = {}, pg } = req
|
7
7
|
const tokenData = await getOpt(req.params.table, req.user?.uid);
|
8
8
|
if (tokenData) {
|
9
|
-
const { rows } = await req.pg.query(`select ${tokenData.columns || '*'} from ${tokenData.table} where ${tokenData.query || 'true'} limit 10`)
|
10
|
-
|
9
|
+
const { rows = [], fields = [] } = await req.pg.query(`select ${tokenData.columns || '*'} from ${tokenData.table} where ${tokenData.query || 'true'} limit 10`);
|
10
|
+
const meta = await getMeta({ pg, table: tokenData.table });
|
11
|
+
const columns = (meta?.columns || fields).map(el => ({ name: el.name, type: pg.pgType?.[el.dataTypeID], title: el.title }));
|
12
|
+
return { rows, columns };
|
11
13
|
}
|
12
14
|
|
13
15
|
// Це можна 1 раз на старті
|
14
16
|
const interfaceName = req.headers?.referer?.match(/.*\/([^?]+)/)?.[1];
|
15
17
|
const { query } = interfaceName ?
|
16
18
|
await req.pg.query(`select query from admin.routes where route_id=$1`, [interfaceName])
|
17
|
-
.then(
|
19
|
+
.then(el => el.rows?.[0] || {}) : {};
|
18
20
|
|
19
21
|
// це можна від користувача
|
20
22
|
const { rows = [] } = pg.pk?.['admin.rules'] ? await req.pg.query(`select attr,(select rule_values from admin.account_grants where account_id in (select account_id from admin.account_users where user_uid=$2) and rule_id=r.rule_id limit 1) from admin.rules r where (select route_id from admin.routes where $1 in (alias,table_name)) = any(routes)`, [req.params.table, user.uid]) : {};
|