@opengis/fastify-table 1.2.1 → 1.2.2

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.2.1",
3
+ "version": "1.2.2",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -11,9 +11,10 @@ export default async function dataDelete({
11
11
  }) {
12
12
  const pg = pg1 || getPG({ name: 'client' });
13
13
  const { pk } = await getMeta({ pg, table });
14
- if (!pg.tlist?.includes(table)) return 'table not exist';
14
+ const table1 = table.replace(/"/g, '');
15
+ if (!pg.tlist?.includes(table1)) return 'table not exist';
15
16
  const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
16
- // console.log(updateDataset);
17
+
17
18
  const res = await pg.query(delQuery, [id]).then(el => el.rows?.[0] || {});
18
19
  await logChanges({
19
20
  pg, table, tokenData, referer, id, uid, type: 'DELETE',
@@ -36,8 +36,16 @@ export default async function dataInsert({
36
36
 
37
37
  const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
38
38
 
39
+ const table1 = pg.pk[table] ? table : table.replace(/"/g, '');
39
40
  await logChanges({
40
- pg, table, tokenData, referer, data, id: res.rows?.[0]?.[pg.pk[table]], uid, type: 'INSERT',
41
+ pg,
42
+ table,
43
+ tokenData,
44
+ referer,
45
+ data,
46
+ id: res.rows?.[0]?.[pg.pk[table1]],
47
+ uid,
48
+ type: 'INSERT',
41
49
  });
42
50
 
43
51
  rclient.incr(`pg:${table}:crud`);
@@ -56,12 +56,17 @@ export default async function getAccess({ table, user = {} }) {
56
56
  return { actions: [], query: '1=1' };
57
57
  }
58
58
 
59
- const userAccess = await pgClients.client.query(q, [table, uid])
60
- .then(el => ({
61
- ...el.rows[0] || {},
62
- roles: el.rows?.map?.(row => row.role_id) || [],
63
- actions: el.rows?.map?.(row => row.actions).flat() || [],
64
- }));
59
+ const userAccess = pgClients.client?.pk?.['admin.routes']
60
+ && pgClients.client?.pk?.['admin.role_access']
61
+ && pgClients.client?.pk?.['admin.roles']
62
+ && pgClients.client?.pk?.['admin.user_roles']
63
+ ? await pgClients.client.query(q, [table, uid])
64
+ .then(el => ({
65
+ ...el.rows[0] || {},
66
+ roles: el.rows?.map?.(row => row.role_id) || [],
67
+ actions: el.rows?.map?.(row => row.actions).flat() || [],
68
+ }))
69
+ : {};
65
70
 
66
71
  const query = userAccess?.scope === 'my' ? `uid='${uid}'` : '1=1';
67
72
  const actions = userAccess?.actions?.filter?.((el, idx, arr) => arr.indexOf(el) === idx && tableActions.includes(el));
@@ -11,8 +11,9 @@ function getValue(val) {
11
11
  // extract titles and cls from form schema
12
12
  // alt: extract table template from referer -> form
13
13
  export default async function logChanges({
14
- pg, table, tokenData, referer, id, data, uid = 1, type,
14
+ pg, table: table1, tokenData, referer, id, data, uid = 1, type,
15
15
  }) {
16
+ const table = table1.replace(/"/g, '');
16
17
  if (!id) {
17
18
  console.error('param id is required');
18
19
  return null;