@opengis/fastify-table 1.1.100 → 1.1.101

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.100",
3
+ "version": "1.1.101",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -6,7 +6,7 @@ import getMeta from '../../pg/funcs/getMeta.js';
6
6
  import logChanges from './utils/logChanges.js';
7
7
 
8
8
  export default async function dataInsert({
9
- table, data, pg: pg1, uid,
9
+ id, table, data, pg: pg1, uid,
10
10
  }) {
11
11
  const pg = pg1 || getPG({ name: 'client' });
12
12
  if (!data) return null;
@@ -16,6 +16,7 @@ export default async function dataInsert({
16
16
  const names = columns.map((el) => el.name);
17
17
 
18
18
  Object.assign(data, {
19
+ ...(id && pg.pk?.[table] ? { [pg.pk?.[table]]: id } : {}),
19
20
  ...(table !== 'admin.users' ? { uid } : {}),
20
21
  // editor_id: uid,
21
22
  });
@@ -52,7 +52,7 @@ export default async function insert(req) {
52
52
  }
53
53
 
54
54
  const res = await dataInsert({
55
- table: loadTemplate?.table || table, data: body, uid: user?.uid,
55
+ id: params?.id, table: loadTemplate?.table || table, data: body, uid: user?.uid,
56
56
  });
57
57
  if (!res) return { message: 'nothing added ' };
58
58
 
@@ -14,7 +14,7 @@ async function plugin(fastify, config = {}) {
14
14
  const prefix = config.prefix || '/api';
15
15
  fastify.put(`${prefix}/table/:table/:id?`, { schema: tableSchema }, update);
16
16
  fastify.delete(`${prefix}/table/:table/:id?`, { schema: tableSchema }, deleteCrud);
17
- fastify.post(`${prefix}/table/:table?`, { schema: tableSchema }, insert);
17
+ fastify.post(`${prefix}/table/:table/:id?`, { schema: tableSchema }, insert);
18
18
  fastify.get(`${prefix}/table/:table/:id?`, { schema: tableSchema }, table);
19
19
  }
20
20