@opengis/fastify-table 1.1.70 → 1.1.71

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/index.js CHANGED
@@ -73,7 +73,8 @@ async function plugin(fastify, opt) {
73
73
 
74
74
  execMigrations().catch(err => console.log(err));
75
75
 
76
- if (!fastify.funcs) {
76
+ // only at fastify-auth
77
+ if (!fastify.funcs && false) {
77
78
  fastify.addHook('onRequest', async (req) => {
78
79
  // req.funcs = fastify;
79
80
  if (!req.user && req.session?.passport?.user) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.70",
3
+ "version": "1.1.71",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -23,7 +23,7 @@ export default async function deleteCrud(req) {
23
23
  }
24
24
  const loadTemplate = await getTemplate('table', del);
25
25
 
26
- const { table } = loadTemplate || hookData || req.params || {};
26
+ const { table } = loadTemplate || hookData || tokenData || req.params || {};
27
27
 
28
28
  if (!table) return { status: 404, message: 'table is required' };
29
29
  if (!id) return { status: 404, message: 'id is required' };
@@ -4,7 +4,7 @@ import {
4
4
 
5
5
  export default async function insert(req) {
6
6
  const {
7
- user, params = {}, body = {},
7
+ user = {}, params = {}, body = {},
8
8
  } = req || {};
9
9
  if (!user) return { message: 'access restricted', status: 403 };
10
10
  const hookData = await applyHook('preInsert', { table: params?.table, user });
@@ -12,7 +12,7 @@ export default async function insert(req) {
12
12
  return { message: hookData?.message, status: hookData?.status };
13
13
  }
14
14
  const tokenData = await getToken({
15
- uid: user.uid, token: params.table, mode: 'a', json: 1,
15
+ uid: user?.uid, token: params.table, mode: 'a', json: 1,
16
16
  });
17
17
 
18
18
  const { form, table: add } = hookData || tokenData || (config.auth?.disable ? req.params : {});
@@ -42,10 +42,8 @@ export default async function insert(req) {
42
42
  return { message: 'Дані містять заборонені символи. Приберіть їх та спробуйте ще раз', status: 409 };
43
43
  }
44
44
 
45
- const uid = user?.uid;
46
-
47
45
  if (![add, table].includes('admin.users')) {
48
- Object.assign(body, { uid, editor_id: uid });
46
+ Object.assign(body, { uid: user?.uid, editor_id: user?.uid });
49
47
  }
50
48
  if (tokenData?.obj) {
51
49
  const objData = tokenData.obj?.split('#').reduce((p, el) => ({ ...p, [el.split('=')[0]]: el.split('=')[1] }), {}) || {};
@@ -53,7 +51,7 @@ export default async function insert(req) {
53
51
  }
54
52
 
55
53
  const res = await dataInsert({
56
- table: loadTemplate?.table || table, data: body, uid,
54
+ table: loadTemplate?.table || table, data: body, uid: user?.uid,
57
55
  });
58
56
  if (!res) return { message: 'nothing added ' };
59
57
 
@@ -69,7 +67,7 @@ export default async function insert(req) {
69
67
  const objId = body[formData[key].parent_id] || req.body?.id;
70
68
  const extraRows = await Promise.all(body[key].map(async (row) => {
71
69
  const extraRes = await dataInsert({
72
- table: formData[key].table, data: { ...row, [formData[key].parent_id]: objId }, uid,
70
+ table: formData[key].table, data: { ...row, [formData[key].parent_id]: objId }, uid: user?.uid,
73
71
  });
74
72
  return extraRes?.rows?.[0];
75
73
  }));
@@ -6,12 +6,12 @@ import {
6
6
  const maxLimit = 100;
7
7
  export default async function dataAPI(req) {
8
8
  const {
9
- pg, params, query = {}, user,
9
+ pg, params, query = {}, user = {},
10
10
  } = req;
11
11
 
12
12
  const time = Date.now();
13
13
 
14
- const uid = config?.auth?.disable ? '1' : user?.uid;
14
+ const { uid } = user;
15
15
 
16
16
  const hookData = await applyHook('preData', {
17
17
  table: params?.table, id: params?.id, user,