@opengis/fastify-table 1.4.11 → 1.4.13

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.11",
3
+ "version": "1.4.13",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -29,7 +29,7 @@ export default function checkPolicy(req, reply) {
29
29
  const { policy = [] } = routeOptions?.config || {};
30
30
 
31
31
  /*= == 0.Check superadmin access === */
32
- if (policy.includes('admin') && user?.user_type !== 'admin') {
32
+ if (policy.includes('admin') && user?.user_type !== 'admin' && !config.auth?.disable) {
33
33
  logger.file('policy/access', {
34
34
  path, method, params, query, body, message: 'access restricted: not admin', uid: user?.uid,
35
35
  });
@@ -22,19 +22,27 @@ export default async function getSelectVal({
22
22
  if (!cls?.sql) return null;
23
23
 
24
24
  // select id column name
25
- if (!selectIds[name]) selectIds[name] = await pg.queryCache(`select * from (${cls.sql})q limit 0`).then((res) => res.fields?.[0]?.name);
25
+ if (!selectIds[name]) {
26
+ selectIds[name] = await pg.queryCache(`select * from (${cls.sql})q limit 0`)
27
+ .then((res) => res.fields?.[0]?.name)
28
+ .catch(err => console.error('getSelectVal error: 1', name, cls.sql, err.toString()));
29
+ }
26
30
  const id = selectIds[name];
27
31
 
28
32
  // cache
29
33
  const key = `select:${name}`;
34
+
30
35
  const cache = values?.length && config.redis ? (await rclient.hmget(key, values)).reduce((p, el, i) => ({ ...p, [values[i]]: el }), {}) : {};
31
36
  const filteredValues = values.filter(el => !cache[el]);
32
37
 
33
38
  // query select
39
+ const q = `with c(id,text) as (select * from (${cls.sql})q where ${id} = any('{${filteredValues.join(',').replace(/\"/g, '\\"').replace(/'/g, "''")}}')) select * from c`;
34
40
 
35
- const q = `with c(id,text) as (select * from (${cls.sql})q where ${id} = any('{${filteredValues.join(',').replace(/\"/g, '\\"')}}')) select * from c`;
36
-
37
- const data = filteredValues.length ? await pg.query(q).then(el => el.rows) : [];
41
+ const data = filteredValues.length
42
+ ? await pg.query(q)
43
+ .then(el => el.rows)
44
+ .catch(err => console.error('getSelectVal error: 2', name, q, err.toString()))
45
+ : [];
38
46
 
39
47
  const clsObj = { ...cache, ...data.reduce((p, el) => ({ ...p, [el.id.toString()]: el.color ? el : el.text }), {}) };
40
48
 
@@ -376,7 +376,7 @@ export default async function dataAPI(req, reply, called) {
376
376
  uid,
377
377
  array: 1,
378
378
  });
379
- Object.assign(res, { addToken: addTokens[0] });
379
+ Object.assign(res, { addToken: addTokens?.[0] });
380
380
  }
381
381
 
382
382
  const result = await applyHook('afterData', {