@opengis/fastify-table 1.4.31 → 1.4.32

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.31",
3
+ "version": "1.4.32",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -50,7 +50,35 @@ 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 = [], panels } = result;
53
+ const { rows = [] } = result;
54
+
55
+ const panels = (index.table && index.query ? index.panels : result?.panels) || [];
56
+
57
+ if (index.table && index.query) {
58
+ // conditions
59
+ panels.filter(panel => panel.items).forEach(el => {
60
+ el.items = el.items?.filter?.(item => conditions(item.conditions, rows[0]));
61
+ });
62
+
63
+ // title, count
64
+ await Promise.all(panels.filter(el => el.items).map(async el => {
65
+ const filtered = el.items.filter(item => item.count?.toLowerCase?.().includes('select'));
66
+
67
+ const data = await Promise.all(filtered.map(async el1 => pg.query(el1.count).then(item => item.rows?.[0] || {})));
68
+
69
+ filtered.forEach((item1, i) => {
70
+ Object.assign(item1, data[i] || {}, data[i].count ? {} : { count: undefined });
71
+ });
72
+
73
+ const q = el.items.map((item2) => (item2.component ? components[item2.component] : null)).filter(item2 => item2).join(' union all ');
74
+
75
+ const counts = q && id
76
+ ? await pg.query(q, [id])
77
+ .then(e => e.rows.reduce((acc, curr) => Object.assign(acc, { [curr.component]: curr.count }), {}))
78
+ : {};
79
+ el.items?.filter?.(item => item.component)?.forEach(item => Object.assign(item, { count: counts?.[item.component] }));
80
+ }));
81
+ }
54
82
 
55
83
  // tokens result
56
84
  const tokens = {};