@opengis/fastify-table 1.4.27 → 1.4.28

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.4.27",
3
+ "version": "1.4.28",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -50,31 +50,7 @@ export default async function getCardData(req, reply) {
50
50
  return reply.status(403).send('access restricted: empty rows');
51
51
  }
52
52
 
53
- const { rows = [] } = result;
54
-
55
- // conditions
56
- index.panels?.filter(el => el.items).forEach(el1 => {
57
- el1.items = el1.items?.filter(item => conditions(item.conditions, rows[0]));
58
- });
59
-
60
- // title, count
61
- index.panels?.filter(el => el.items).forEach(async el => {
62
- const filtered = el.items.filter(item => item.count?.toLowerCase?.().includes('select'));
63
-
64
- const data = await Promise.all(filtered.map(el1 => pg.query(el1.count).then(item => item.rows?.[0] || {})));
65
-
66
- filtered.forEach((item1, i) => {
67
- Object.assign(item1, data[i] || {}, data[i].count ? {} : { count: undefined });
68
- });
69
-
70
- const q = el.items.map((item2) => (item2.component ? components[item2.component] : null)).filter(item2 => item2).join(' union all ');
71
-
72
- const counts = q && id
73
- ? await pg.query(q, [id])
74
- .then(e => e.rows.reduce((acc, curr) => Object.assign(acc, { [curr.component]: curr.count }), {}))
75
- : {};
76
- el.items?.filter?.(item => item.component)?.forEach(item => Object.assign(item, { count: counts?.[item.component] }));
77
- });
53
+ const { rows = [], panels } = result;
78
54
 
79
55
  // tokens result
80
56
  const tokens = {};
@@ -137,6 +113,7 @@ export default async function getCardData(req, reply) {
137
113
  return {
138
114
  time: Date.now() - time,
139
115
  ...index,
116
+ panels,
140
117
  tokens,
141
118
  vue,
142
119
  data,
@@ -17,14 +17,6 @@ const checkInline = {};
17
17
  const maxLimit = 100;
18
18
  const defaultLimit = 20;
19
19
 
20
- function getOrder(query, columnList, orderColumn, loadTable, orderDir, called) {
21
- if (query?.order && called) { return `order by ${query.order}`; }
22
- if (typeof orderColumn === 'string' && Array.isArray(columnList) && columnList.includes(orderColumn)) {
23
- return `order by ${orderColumn} ${query?.desc || orderDir === 'desc' ? 'desc' : ''} nulls last`;
24
- }
25
- return `order by ${(loadTable?.order || 'true::boolean')} nulls last`;
26
- }
27
-
28
20
  export default async function dataAPI(req, reply, called) {
29
21
  const {
30
22
  pg = pgClients.client, params, headers = {}, query = {}, user = {}, contextQuery, sufix = true,
@@ -174,8 +166,9 @@ export default async function dataAPI(req, reply, called) {
174
166
  // id, query, filter
175
167
  const [orderColumn, orderDir] = (query.order || loadTable?.order || '').split(/[- ]/);
176
168
 
177
- const order = getOrder(query, columnList, orderColumn, loadTable, orderDir, called);
178
-
169
+ const order = query.order && columnList.includes(orderColumn) && orderColumn?.length
170
+ ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''} nulls last`
171
+ : `order by ${(loadTable?.order || 'true::boolean')} nulls last`;
179
172
  const search = loadTable?.meta?.search && query.search
180
173
  ? `(${loadTable?.meta?.search?.split(',')?.map(el => `${el} ilike '%${query.search.replace(/%/g, '\\%').replace(/'/g, "''")}%'`).join(' or ')})`
181
174
  : null;
@@ -269,6 +262,7 @@ export default async function dataAPI(req, reply, called) {
269
262
  const { panels = [] } = index;
270
263
 
271
264
  const tokens = {};
265
+
272
266
  if (template && objectId) {
273
267
  // tokens result
274
268
  if (!config.security?.disableToken && index?.tokens && typeof index?.tokens === 'object' && !Array.isArray(index?.tokens)) {
@@ -300,19 +294,20 @@ export default async function dataAPI(req, reply, called) {
300
294
  });
301
295
 
302
296
  // title, count
303
- panels?.filter(el => el.items).forEach(async el => {
297
+ await Promise.all(panels.filter(el => el.items).map(async el => {
304
298
  const filtered1 = el.items.filter(item => item.count?.toLowerCase?.().includes('select'));
305
- const data = await Promise.all(filtered1.map(item => pg.query(item.count.replace(/{{id}}/g, params.id)).then(item1 => item1.rows[0] || {})));
299
+ const data = await Promise.all(filtered1.map(async item => pg.query(item.count.replace(/{{id}}/g, params.id)).then(item1 => item1.rows[0] || {})));
306
300
  filtered1.forEach((el1, i) => {
301
+ // el1.title = data[i].title;
307
302
  Object.assign(el1, data[i] || {}, data[i].count ? {} : { count: undefined });
308
303
  });
309
304
  const q1 = el.items.map((item) => (item.component ? components[item.component] : null)).filter(item => item).join(' union all ');
310
305
  const counts1 = q1 && id
311
- ? await pg.query(q, [id])
306
+ ? await pg.query(q1, [id])
312
307
  .then(e => e.rows.reduce((acc, curr) => Object.assign(acc, { [curr.component]: curr.count }), {}))
313
308
  : {};
314
309
  el.items?.filter?.(item => item.component)?.forEach(item => Object.assign(item, { count: counts1?.[item.component] }));
315
- });
310
+ }));
316
311
 
317
312
  // data result
318
313
  const data = {};