@opengis/fastify-table 1.1.107 → 1.1.109

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.1.107",
3
+ "version": "1.1.109",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -20,6 +20,7 @@ ALTER TABLE admin.users add column if not exists user_personal_code text;
20
20
  ALTER TABLE admin.users add column if not exists last_activity_date timestamp without time zone;
21
21
  ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
22
22
  ALTER TABLE admin.users add column if not exists user_rnokpp text;
23
+ ALTER TABLE admin.users alter column user_rnokpp drop not null;
23
24
  ALTER TABLE admin.users add column if not exists salt text;
24
25
  ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
25
26
  ALTER TABLE admin.users add column if not exists editor_id text;
@@ -1,3 +1,5 @@
1
+ import { handlebars } from '@opengis/fastify-hb/utils.js';
2
+
1
3
  import getTemplate from '../getTemplate.js';
2
4
  import getSelectVal from './getSelectVal.js';
3
5
 
@@ -7,8 +9,15 @@ export default async function metaFormat({ rows, table }) {
7
9
  const loadTable = await getTemplate('table', table);
8
10
  const selectCols = loadTable?.columns?.filter((e) => e.data);
9
11
  const metaCls = Object.keys(loadTable?.meta?.cls || {}).map((el) => ({ name: el, data: loadTable?.meta?.cls[el] }));
10
- if (!selectCols?.length && !metaCls?.length) return rows;
11
-
12
+ const htmlCols = loadTable?.columns?.filter((e) => e.name && e.format === 'html' && e.html);
13
+ if (!selectCols?.length && !metaCls?.length && !htmlCols?.length) return rows;
14
+
15
+ await Promise.all(htmlCols?.map(async (attr) => {
16
+ await Promise.all(rows.filter(row => row?.[attr.name])?.map(async (row) => {
17
+ const html = await handlebars.compile(attr.html)(row);
18
+ Object.assign(row, { [attr.name]: html?.replaceAll(/<[^>]*>/g, '')?.replace(/\n/g, '')?.trim() });
19
+ }));
20
+ }));
12
21
  // cls & select format
13
22
 
14
23
  await Promise.all(selectCols.concat(metaCls)?.map(async (attr) => {
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  applyHook, getAccess, getTemplate, checkXSS, dataInsert, getToken, config,
3
+ pgClients,
3
4
  } from '../../../../utils.js';
4
5
 
5
6
  export default async function insert(req) {
@@ -61,7 +62,8 @@ export default async function insert(req) {
61
62
  table, token: params?.table, body, payload: res, user,
62
63
  });
63
64
  // form DataTable
64
- const extraKeys = Object.keys(schema || {})?.filter((key) => schema?.[key]?.type === 'DataTable' && schema?.[key]?.table && schema?.[key]?.parent_id && body[key].length);
65
+ const extraKeys = Object.keys(schema || {})?.filter((key) => schema?.[key]?.type === 'DataTable' && schema?.[key]?.table && schema?.[key]?.parent_id && body[key]?.length);
66
+
65
67
  if (extraKeys?.length) {
66
68
  res.extra = {};
67
69
  await Promise.all(extraKeys?.map(async (key) => {
@@ -76,5 +78,6 @@ export default async function insert(req) {
76
78
  }));
77
79
  }
78
80
 
79
- return { rows: res.rows, extra: res.extra };
81
+ const pk = pgClients.client?.pk?.[loadTemplate?.table || table];
82
+ return { id: res?.rows?.[0]?.[pk], rows: res.rows, extra: res.extra };
80
83
  }