@opengis/fastify-table 1.2.76 → 1.2.77
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/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import routeData from '../../../routes/table/controllers/data.js';
|
|
2
2
|
|
|
3
|
-
export default async function getData({ id, table, pg, filter, limit, page, search, user, sql }, reply, called) {
|
|
3
|
+
export default async function getData({ id, table, pg, filter, limit, page, search, user, sql, contextQuery }, reply, called) {
|
|
4
4
|
const params = { table, id };
|
|
5
5
|
const query = { filter, limit, page, search, sql };
|
|
6
|
-
const result = await routeData({ pg, params, query, user,
|
|
6
|
+
const result = await routeData({ pg, params, query, user, contextQuery }, reply, called);
|
|
7
7
|
return result;
|
|
8
8
|
}
|
|
@@ -15,7 +15,7 @@ const checkInline = {};
|
|
|
15
15
|
const maxLimit = 100;
|
|
16
16
|
export default async function dataAPI(req, reply, called) {
|
|
17
17
|
const {
|
|
18
|
-
pg = pgClients.client, params, query = {}, user = {},
|
|
18
|
+
pg = pgClients.client, params, query = {}, user = {}, contextQuery,
|
|
19
19
|
} = req;
|
|
20
20
|
|
|
21
21
|
const time = Date.now();
|
|
@@ -130,7 +130,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
130
130
|
const bbox = meta?.bbox && queryBbox.filter((el) => !Number.isNaN(el))?.length === 4 ? `${meta.bbox} && 'box(${queryBbox[0]} ${queryBbox[1]},${queryBbox[2]} ${queryBbox[3]})'::box2d ` : undefined;
|
|
131
131
|
|
|
132
132
|
const interfaceQuery = params?.query ? await handlebars.compile(params?.query)({ user, uid }) : undefined;
|
|
133
|
-
const where = [(tokenData?.id || hookData?.id || params.id ? ` "${pk}" = $1` : null), keyQuery, loadTable?.query, tokenData?.query, fData.q, search, accessQuery || '1=1', bbox, queryPolyline, interfaceQuery].filter((el) => el).filter((el) => (user?.user_type === 'superadmin' ? !el.includes('{{uid}}') : true));
|
|
133
|
+
const where = [(tokenData?.id || hookData?.id || params.id ? ` "${pk}" = $1` : null), keyQuery, loadTable?.query, tokenData?.query, fData.q, search, accessQuery || '1=1', contextQuery, bbox, queryPolyline, interfaceQuery].filter((el) => el).filter((el) => (user?.user_type === 'superadmin' ? !el.includes('{{uid}}') : true));
|
|
134
134
|
|
|
135
135
|
// const cardColumns = cardSqlFiltered.length ? `,${cardSqlFiltered.map((el) => el.name)}` : '';
|
|
136
136
|
const q = `select ${pk ? `"${pk}" as id,` : ''}
|
|
@@ -146,7 +146,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
146
146
|
.replace(/{{uid}}/g, uid);
|
|
147
147
|
|
|
148
148
|
// if (user?.user_type === 'superadmin') console.log(q);
|
|
149
|
-
|
|
149
|
+
if (config.trace) console.log(q);
|
|
150
150
|
if (query.sql === '1') { return q; }
|
|
151
151
|
|
|
152
152
|
const { rows = [] } = await pg.query(q, (tokenData?.id || hookData?.id || params.id ? [tokenData?.id || hookData?.id || params.id] : null) || (query.key && loadTable.key ? [query.key] : []));
|
|
@@ -172,7 +172,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
172
172
|
count(*) FILTER(WHERE ${filterWhere.join(' and ') || 'true'})::int as filtered
|
|
173
173
|
${aggregates.length ? `,${aggregates.map((el) => `${aggColumns[el.name]}(${el.name}) FILTER(WHERE ${filterWhere.join(' and ') || 'true'}) as ${el.name}`).join(',')}` : ''}
|
|
174
174
|
from (select * ${sql?.filter(el => el.inline).map(el => `,(${el.sql})`).join('') || ''} from ${table} t ${sqlTable})q
|
|
175
|
-
where ${[loadTable?.query, tokenData?.query, accessQuery].filter(el => el).join(' and ') || 'true'} `
|
|
175
|
+
where ${[loadTable?.query, tokenData?.query, accessQuery, contextQuery].filter(el => el).join(' and ') || 'true'} `
|
|
176
176
|
.replace(/{{uid}}/g, uid);
|
|
177
177
|
|
|
178
178
|
if (query.sql === '2') { return qCount; }
|