@opengis/fastify-table 1.0.79 → 1.0.80

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/Changelog.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # fastify-table
2
2
 
3
- ## 1.0.79 - 15.08.2024
3
+ ## 1.0.80 - 15.08.2024
4
4
 
5
5
  - refactor /table API
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.0.79",
3
+ "version": "1.0.80",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -18,7 +18,7 @@ export default async function dataAPI(req) {
18
18
  if (!loadTable) { return { message: 'template not found', status: 404 }; }
19
19
 
20
20
  const {
21
- table, columns, sql, cardSql, filters, form, meta, sqlColumns,
21
+ table, columns, sql, cardSql, filters, form, meta, sqlColumns, ispublic,
22
22
  } = loadTable;
23
23
  const { pk, columns: dbColumns = [] } = await getMeta(table);
24
24
 
@@ -75,7 +75,7 @@ export default async function dataAPI(req) {
75
75
  const addTokens = setToken({
76
76
  ids: [JSON.stringify({ add: loadTable.table, form: loadTable.form })],
77
77
  mode: 'a',
78
- uid,
78
+ uid: funcs.config?.auth?.disable || ispublic ? '1' : uid,
79
79
  array: 1,
80
80
  });
81
81
  Object.assign(res, { addToken: addTokens[0] });
@@ -84,7 +84,7 @@ export default async function dataAPI(req) {
84
84
  const editTokens = setToken({
85
85
  ids: [JSON.stringify({ id: row.id, table: loadTable.table, form: loadTable.form })],
86
86
  mode: 'w',
87
- uid,
87
+ uid: funcs.config?.auth?.disable || ispublic ? '1' : uid,
88
88
  array: 1,
89
89
  });
90
90
  Object.assign(row, { token: editTokens[0] });
@@ -7,14 +7,16 @@ export default async function tableAPI(req) {
7
7
  } = req;
8
8
  if (!params.id) return { message: 'not enough params', status: 400 };
9
9
 
10
- const loadTable = await getTemplate('table', opt?.table || params.table);
11
- if (!loadTable) { return { message: 'not found', status: 404 }; }
10
+ const loadTable = await getTemplate('table', opt?.table || params.table) || {};
11
+ if (!loadTable) {
12
+ if (!pg.pk?.[opt?.table || params.table]) { return { message: 'not found', status: 404 }; }
13
+ }
12
14
 
13
15
  const {
14
16
  table, /* columns, */ form,
15
17
  } = loadTable;
16
18
 
17
- const { pk, columns: dbColumns = [] } = await getMeta(table);
19
+ const { pk, columns: dbColumns = [] } = await getMeta(table || opt?.table || params.table);
18
20
  if (!pk) return { message: `table not found: ${table}`, status: 404 };
19
21
 
20
22
  // const cols = columns.map((el) => el.name || el).join(',');
@@ -27,7 +29,7 @@ export default async function tableAPI(req) {
27
29
  const cols = Object.keys(schema || {}).filter((col) => columnList.includes(col) && !extraKeys.includes(col))?.join(',');
28
30
  const where = [`"${pk}" = $1`, loadTable.query].filter((el) => el);
29
31
  const geom = columnList.includes('geom') ? 'st_asgeojson(geom)::json as geom,' : '';
30
- const q = `select "${pk}" as id, ${geom} ${cols || '*'} from ${table} t where ${where.join(' and ') || 'true'} limit 1`;
32
+ const q = `select "${pk}" as id, ${geom} ${cols || '*'} from ${table || opt?.table || params.table} t where ${where.join(' and ') || 'true'} limit 1`;
31
33
 
32
34
  if (query.sql === '1') return q;
33
35