@opengis/fastify-table 1.2.5 → 1.2.7
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
|
@@ -37,13 +37,17 @@ export default async function getAccess({ table, user = {} }) {
|
|
|
37
37
|
|
|
38
38
|
const { uid, user_type: userType = 'regular' } = user;
|
|
39
39
|
|
|
40
|
-
if (userType
|
|
40
|
+
if (userType === 'superadmin') {
|
|
41
41
|
return { actions: ['view', 'edit', 'add', 'del'], query: '1=1' };
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const body = await getTemplate('table', table);
|
|
45
45
|
const tableActions = ['view'].concat(body?.actions || body?.action_default || []);
|
|
46
46
|
|
|
47
|
+
if (userType === 'admin') {
|
|
48
|
+
return { actions: body?.actions || body?.action_default ? tableActions : ['view', 'edit', 'add', 'del'], query: '1=1' };
|
|
49
|
+
}
|
|
50
|
+
|
|
47
51
|
if (body?.public || body?.access === 'public') {
|
|
48
52
|
return { actions: tableActions, query: '1=1' };
|
|
49
53
|
}
|
|
@@ -2,15 +2,17 @@ import getTemplate from '../../..//table/funcs/getTemplate.js';
|
|
|
2
2
|
import { metaFormat } from '@opengis/fastify-table/utils.js';
|
|
3
3
|
|
|
4
4
|
const defaultTitles = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
editor_date: 'Дата оновлення',
|
|
6
|
+
editor_id: 'Редактор',
|
|
7
|
+
сdate: 'Дата створення',
|
|
8
|
+
uid: 'Автор',
|
|
9
9
|
body: 'Зміст',
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
entity_id: 'ID Сутності',
|
|
11
|
+
entity_type: 'Таблиця сутності',
|
|
12
12
|
file_path: 'Шлях до файлу',
|
|
13
13
|
uploaded_name: 'Назва файлу',
|
|
14
|
+
size: 'Розмір файлу',
|
|
15
|
+
ext: 'Розширення файлу',
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
function getValue(val) {
|
|
@@ -1,37 +1,53 @@
|
|
|
1
1
|
|
|
2
2
|
const emailReg = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/g;
|
|
3
3
|
|
|
4
|
-
function checkField(key, val, options) {
|
|
4
|
+
function checkField(key, val, options, idx) {
|
|
5
5
|
// validators: [required]
|
|
6
6
|
if (options?.validators?.includes('required') && !val) {
|
|
7
|
-
return {
|
|
7
|
+
return {
|
|
8
|
+
error: 'empty required', key, idx,
|
|
9
|
+
};
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
// validators: [email] / type: Email
|
|
11
13
|
if ((options.type?.toLowerCase() === 'email' || options?.validators?.includes('email')) && val && !val.match(emailReg)) {
|
|
12
|
-
return {
|
|
14
|
+
return {
|
|
15
|
+
error: 'invalid email', key, val, idx,
|
|
16
|
+
};
|
|
13
17
|
}
|
|
18
|
+
return { key, val, idx };
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const check = body
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
function checkBody({ body = {}, arr = [], idx }) {
|
|
22
|
+
const res = Object.keys(body).reduce((acc1, key) => {
|
|
23
|
+
const input = arr.find(el => el.key === key) || {};
|
|
24
|
+
|
|
25
|
+
if (input.colModel?.length && input.type?.toLowerCase() === 'datatable') {
|
|
26
|
+
const result = body[key].reduce((acc, item, i) => {
|
|
27
|
+
const check = checkBody({ body: item, arr: input.colModel, idx: i });
|
|
28
|
+
acc.push(check);
|
|
29
|
+
return acc;
|
|
30
|
+
}, []);
|
|
31
|
+
acc1 = acc1.concat(result);
|
|
32
|
+
return acc1;
|
|
25
33
|
}
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
|
|
35
|
+
const check = checkField(key, body[key], input, idx) || {};
|
|
36
|
+
acc1.push({ key, val: body[key], ...check });
|
|
37
|
+
return acc1;
|
|
28
38
|
}, []);
|
|
29
39
|
|
|
30
|
-
const invalidField =
|
|
40
|
+
const invalidField = res.find(el => el.error);
|
|
31
41
|
|
|
32
42
|
if (invalidField) {
|
|
33
|
-
|
|
43
|
+
console.warn('invalid field: ', invalidField.key, invalidField.error);
|
|
44
|
+
return invalidField;
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
return { message: 'ok' };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default function validateData({ body = {}, schema = {} }) {
|
|
51
|
+
const res = checkBody({ body, arr: Object.keys(schema).map(key => ({ ...schema[key], key })) });
|
|
52
|
+
return res;
|
|
37
53
|
}
|
|
@@ -28,7 +28,7 @@ export default async function metaFormat({
|
|
|
28
28
|
if (!clsValues) return null;
|
|
29
29
|
|
|
30
30
|
rows.forEach(el => {
|
|
31
|
-
const val = el[attr.name]?.map?.(c => clsValues[c.toString()] || clsValues[c] || c) || clsValues[el[attr.name]?.toString()] || clsValues[el[attr.name]] || el[attr.name];
|
|
31
|
+
const val = el[attr.name]?.map?.(c => c ? clsValues[c.toString()] || clsValues[c] || c : null) || clsValues[el[attr.name]?.toString()] || clsValues[el[attr.name]] || el[attr.name];
|
|
32
32
|
if (!val) return;
|
|
33
33
|
if (!sufix) {
|
|
34
34
|
Object.assign(el, { [attr.name]: val.text || val });
|