@opengis/admin 0.3.21 → 0.3.23
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/dist/{add-page-DsqxZzEq.js → add-page-2cPkdIAC.js} +29 -26
- package/dist/{admin-interface-C8SGlC1N.js → admin-interface-D9Dx7QqK.js} +234 -232
- package/dist/{admin-view-DtdqTUPa.js → admin-view-C_Ecdip-.js} +29 -29
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +88 -88
- package/dist/{card-view-juhvChuX.js → card-view-MuS2Gqq6.js} +3 -3
- package/dist/{edit-page-DB1hlRzp.js → edit-page-Dr397YuE.js} +33 -31
- package/dist/{import-file-BSdaeh6s.js → import-file-CcRnsq1s.js} +23212 -23090
- package/dist/{profile-page-B-RhB5JP.js → profile-page-BrKTAsqO.js} +2 -2
- package/dist/style.css +1 -1
- package/module/settings/card/admin.roles.table/access.hbs +11 -11
- package/module/settings/card/admin.roles.table/general_info.hbs +9 -9
- package/module/settings/card/admin.roles.table/index.yml +22 -22
- package/module/settings/card/admin.roles.table/users.hbs +12 -12
- package/module/settings/card/admin.routes.table/general_info.hbs +13 -13
- package/module/settings/card/admin.routes.table/index.yml +15 -15
- package/module/settings/card/admin.table_properties.table/custom_columns.hbs +22 -22
- package/module/settings/card/admin.table_properties.table/index.yml +12 -12
- package/module/settings/card/admin.table_properties.table/info.hbs +17 -17
- package/module/settings/card/admin.users.table/general_info.hbs +18 -18
- package/module/settings/card/admin.users.table/index.yml +20 -20
- package/module/settings/card/admin.users.table/last_login.hbs +17 -17
- package/module/settings/card/admin.users.table/logs.hbs +16 -16
- package/module/settings/card/admin.users.table/routes.hbs +13 -13
- package/module/settings/card/admin.users.table/user_roles.hbs +35 -35
- package/module/settings/cls/change_type.json +13 -13
- package/module/settings/cls/core.column_type.json +14 -14
- package/module/settings/form/admin.custom_column.form.json +55 -55
- package/module/settings/form/admin.routes.form.json +25 -25
- package/module/settings/form/admin.rules.form.json +30 -30
- package/module/settings/form/admin.table_properties.form.json +19 -19
- package/module/settings/form/admin.user_roles.form.json +24 -24
- package/module/settings/form/admin.users.form.json +177 -177
- package/module/settings/form/admin.users_edit.form.json +145 -145
- package/module/settings/form/context.account_grants.form.json +24 -24
- package/module/settings/form/context.account_users.form.json +12 -12
- package/module/settings/form/user.user_roles.form.json +13 -13
- package/module/settings/menu.json +72 -72
- package/module/settings/table/admin.accounts.table.json +49 -49
- package/module/settings/table/admin.custom_column.table.json +100 -100
- package/module/settings/table/admin.roles.table.json +77 -77
- package/module/settings/table/admin.routes.table.json +73 -73
- package/module/settings/table/admin.rules.table.json +77 -77
- package/module/settings/table/admin.table_properties.table.json +37 -37
- package/module/settings/table/admin.user_roles.table.json +74 -74
- package/module/settings/table/admin.users.table.json +135 -135
- package/module/settings/table/context.account_grants.table.json +88 -88
- package/module/settings/table/context.account_users.table.json +53 -53
- package/module/settings/table/log.table_changes.table.json +100 -100
- package/package.json +102 -102
- package/plugin.js +30 -30
- package/server/helpers/index.js +40 -40
- package/server/helpers/list/descriptionList.js +45 -45
- package/server/helpers/list/tableList.js +82 -82
- package/server/helpers/list/utils/buttonDel.js +12 -12
- package/server/helpers/list/utils/buttonEdit.js +14 -14
- package/server/helpers/utils/buttonAdd.js +6 -6
- package/server/helpers/utils/buttonDel.js +6 -6
- package/server/helpers/utils/buttonEdit.js +5 -5
- package/server/helpers/utils/paddingNumber.js +3 -3
- package/server/plugins/access/funcs/getAdminAccess.js +12 -12
- package/server/plugins/hook.js +276 -275
- package/server/plugins/vite.js +77 -77
- package/server/routes/access/controllers/access.interface.js +33 -33
- package/server/routes/data/controllers/cardData.js +127 -127
- package/server/routes/data/controllers/tableFilter.js +9 -9
- package/server/routes/data/controllers/tableInfo.js +112 -112
- package/server/routes/dblist/controllers/readItems.js +20 -20
- package/server/routes/dblist/controllers/setItem.js +22 -22
- package/server/routes/dblist/index.mjs +18 -18
- package/server/routes/dblist/utils/formatData.js +7 -7
- package/server/routes/menu/controllers/getMenu.js +77 -77
- package/server/routes/menu/controllers/interfaces.js +20 -20
- package/server/routes/menu/index.mjs +7 -7
- package/server/routes/print/controllers/printTemplate.add.js +37 -37
- package/server/routes/print/controllers/printTemplate.delete.js +29 -29
- package/server/routes/print/controllers/printTemplate.edit.js +42 -42
- package/server/routes/print/controllers/printTemplate.js +67 -67
- package/server/routes/print/controllers/printTemplateList.js +19 -19
- package/server/routes/print/controllers/printTemplatePreview.js +87 -87
- package/server/routes/print/index.mjs +19 -19
- package/server/routes/properties/controllers/admin.properties.get.js +31 -31
- package/server/routes/properties/controllers/table.properties.get.js +120 -120
- package/server/routes/properties/controllers/table.properties.post.js +115 -115
- package/server/routes/properties/controllers/user.properties.get.js +19 -19
- package/server/routes/properties/controllers/user.properties.post.js +10 -10
- package/server/routes/properties/index.mjs +21 -21
- package/server/routes/properties/utils/dataInsert.js +26 -26
- package/server/routes/properties/utils/getColumnMetaData.js +17 -17
- package/server/routes/properties/utils/refreshData.js +128 -128
- package/server/routes/report/utils/getFilterQuery.js +67 -67
- package/server/routes/templates/index.mjs +16 -16
- package/server/routes/user/controllers/user.cls.post.js +54 -54
- package/server/routes/util/index.mjs +5 -5
- package/server/routes/widget/controllers/widget.get.js +125 -125
- package/server/templates/form/admin.profile.form.json +31 -31
- package/server/templates/form/cp_building.form.json +32 -32
- package/server/templates/pt/card-print.pt.hbs +245 -245
- package/utils.js +26 -26
@@ -1,128 +1,128 @@
|
|
1
|
-
import { randomUUID, createHash } from 'crypto';
|
2
|
-
|
3
|
-
import { dataInsert, pgClients } from '@opengis/fastify-table/utils.js';
|
4
|
-
|
5
|
-
function prepareResult(res) {
|
6
|
-
const arr = (res.rows || (Array.isArray(res) ? res : Object.values(res || {})));
|
7
|
-
return {
|
8
|
-
command: 'INSERT',
|
9
|
-
count: res?.rowCount || arr.filter((el) => el.command === 'INSERT')
|
10
|
-
?.map((el) => ({ result: 'success', count: el.rowCount }))
|
11
|
-
?.reduce((acc, curr) => acc + curr.count, 0),
|
12
|
-
};
|
13
|
-
}
|
14
|
-
|
15
|
-
export default async function refreshData({
|
16
|
-
pg = pgClients.client, entity, table, uid, data,
|
17
|
-
}) {
|
18
|
-
if (!['filter', 'column', 'customQuery', 'customColumn'].includes(entity)) {
|
19
|
-
return { message: 'invalid params: entity', status: 400 };
|
20
|
-
}
|
21
|
-
|
22
|
-
const client = await pg.connect();
|
23
|
-
|
24
|
-
/* getMeta support */
|
25
|
-
client.options = pg.options;
|
26
|
-
client.tlist = pg.tlist;
|
27
|
-
client.pgType = pg.pgType;
|
28
|
-
client.pk = pg.pk;
|
29
|
-
client.relkinds = pg.relkinds;
|
30
|
-
|
31
|
-
const result = {};
|
32
|
-
|
33
|
-
try {
|
34
|
-
await client.query('BEGIN');
|
35
|
-
|
36
|
-
if (['filter', 'column'].includes(entity)) {
|
37
|
-
data?.forEach((el) => Object.assign(el, { id: el.id || randomUUID() }));
|
38
|
-
await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
|
39
|
-
|
40
|
-
const res = await dataInsert({
|
41
|
-
pg: client,
|
42
|
-
table: 'setting.property',
|
43
|
-
data: {
|
44
|
-
property_entity: entity,
|
45
|
-
object_id: table,
|
46
|
-
property_json: JSON.stringify(data), // ?.replace(/'+/g, "'")?.replace(/'/g, "''")
|
47
|
-
},
|
48
|
-
uid,
|
49
|
-
});
|
50
|
-
Object.assign(result, res);
|
51
|
-
}
|
52
|
-
|
53
|
-
if (['customQuery'].includes(entity)) {
|
54
|
-
await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
|
55
|
-
|
56
|
-
const res = await Promise.all(data?.map(async (el) => dataInsert({
|
57
|
-
pg: client,
|
58
|
-
table: 'setting.property',
|
59
|
-
data: {
|
60
|
-
property_entity: entity,
|
61
|
-
object_id: table,
|
62
|
-
property_key: el.name,
|
63
|
-
property_text: el.query,
|
64
|
-
property_json: { disabled: el.disabled },
|
65
|
-
},
|
66
|
-
uid,
|
67
|
-
})));
|
68
|
-
Object.assign(result, res);
|
69
|
-
}
|
70
|
-
|
71
|
-
if (entity === 'customColumn') {
|
72
|
-
const prefix = createHash('md5').update(table).digest('hex').substr(0, 10);
|
73
|
-
const data1 = [];
|
74
|
-
|
75
|
-
await Promise.all(data.map(async (el, index) => {
|
76
|
-
const obj = {
|
77
|
-
cf_id: `col_${prefix}_${index}`,
|
78
|
-
cf_name: el.title || el.ua || el.name,
|
79
|
-
cf_type: el.format || el.type,
|
80
|
-
cf_default: el.default,
|
81
|
-
cf_notnull: el.notnull,
|
82
|
-
object_id: table,
|
83
|
-
tablename: table,
|
84
|
-
};
|
85
|
-
|
86
|
-
data1.push({
|
87
|
-
name: obj.cf_id,
|
88
|
-
title: obj.cf_name,
|
89
|
-
format: obj.cf_type,
|
90
|
-
option: data[index]?.option,
|
91
|
-
hidden: data[index]?.hidden,
|
92
|
-
custom: true,
|
93
|
-
});
|
94
|
-
|
95
|
-
await dataInsert({
|
96
|
-
pg: client,
|
97
|
-
table: 'setting.custom_field',
|
98
|
-
data: obj,
|
99
|
-
uid,
|
100
|
-
});
|
101
|
-
}));
|
102
|
-
|
103
|
-
await client.query('delete from setting.custom_field where $1 in (tablename, object_id)', [table]);
|
104
|
-
await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
|
105
|
-
|
106
|
-
const data2 = JSON.stringify(data1?.filter((value, index, array) => array.indexOf(value) === index)); // ?.replace(/'+/g, "'")?.replace(/'/g, "''")
|
107
|
-
const res = await dataInsert({
|
108
|
-
pg: client,
|
109
|
-
table: 'setting.property',
|
110
|
-
data: {
|
111
|
-
property_entity: 'customColumn',
|
112
|
-
object_id: table,
|
113
|
-
property_json: data2,
|
114
|
-
},
|
115
|
-
uid,
|
116
|
-
});
|
117
|
-
Object.assign(result, res);
|
118
|
-
}
|
119
|
-
await client.query('COMMIT');
|
120
|
-
return prepareResult(result);
|
121
|
-
} catch (err) {
|
122
|
-
await client.query('ROLLBACK');
|
123
|
-
return { error: err.toString(), status: 500 };
|
124
|
-
}
|
125
|
-
finally {
|
126
|
-
client.release();
|
127
|
-
}
|
128
|
-
};
|
1
|
+
import { randomUUID, createHash } from 'crypto';
|
2
|
+
|
3
|
+
import { dataInsert, pgClients } from '@opengis/fastify-table/utils.js';
|
4
|
+
|
5
|
+
function prepareResult(res) {
|
6
|
+
const arr = (res.rows || (Array.isArray(res) ? res : Object.values(res || {})));
|
7
|
+
return {
|
8
|
+
command: 'INSERT',
|
9
|
+
count: res?.rowCount || arr.filter((el) => el.command === 'INSERT')
|
10
|
+
?.map((el) => ({ result: 'success', count: el.rowCount }))
|
11
|
+
?.reduce((acc, curr) => acc + curr.count, 0),
|
12
|
+
};
|
13
|
+
}
|
14
|
+
|
15
|
+
export default async function refreshData({
|
16
|
+
pg = pgClients.client, entity, table, uid, data,
|
17
|
+
}) {
|
18
|
+
if (!['filter', 'column', 'customQuery', 'customColumn'].includes(entity)) {
|
19
|
+
return { message: 'invalid params: entity', status: 400 };
|
20
|
+
}
|
21
|
+
|
22
|
+
const client = await pg.connect();
|
23
|
+
|
24
|
+
/* getMeta support */
|
25
|
+
client.options = pg.options;
|
26
|
+
client.tlist = pg.tlist;
|
27
|
+
client.pgType = pg.pgType;
|
28
|
+
client.pk = pg.pk;
|
29
|
+
client.relkinds = pg.relkinds;
|
30
|
+
|
31
|
+
const result = {};
|
32
|
+
|
33
|
+
try {
|
34
|
+
await client.query('BEGIN');
|
35
|
+
|
36
|
+
if (['filter', 'column'].includes(entity)) {
|
37
|
+
data?.forEach((el) => Object.assign(el, { id: el.id || randomUUID() }));
|
38
|
+
await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
|
39
|
+
|
40
|
+
const res = await dataInsert({
|
41
|
+
pg: client,
|
42
|
+
table: 'setting.property',
|
43
|
+
data: {
|
44
|
+
property_entity: entity,
|
45
|
+
object_id: table,
|
46
|
+
property_json: JSON.stringify(data), // ?.replace(/'+/g, "'")?.replace(/'/g, "''")
|
47
|
+
},
|
48
|
+
uid,
|
49
|
+
});
|
50
|
+
Object.assign(result, res);
|
51
|
+
}
|
52
|
+
|
53
|
+
if (['customQuery'].includes(entity)) {
|
54
|
+
await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
|
55
|
+
|
56
|
+
const res = await Promise.all(data?.map(async (el) => dataInsert({
|
57
|
+
pg: client,
|
58
|
+
table: 'setting.property',
|
59
|
+
data: {
|
60
|
+
property_entity: entity,
|
61
|
+
object_id: table,
|
62
|
+
property_key: el.name,
|
63
|
+
property_text: el.query,
|
64
|
+
property_json: { disabled: el.disabled },
|
65
|
+
},
|
66
|
+
uid,
|
67
|
+
})));
|
68
|
+
Object.assign(result, res);
|
69
|
+
}
|
70
|
+
|
71
|
+
if (entity === 'customColumn') {
|
72
|
+
const prefix = createHash('md5').update(table).digest('hex').substr(0, 10);
|
73
|
+
const data1 = [];
|
74
|
+
|
75
|
+
await Promise.all(data.map(async (el, index) => {
|
76
|
+
const obj = {
|
77
|
+
cf_id: `col_${prefix}_${index}`,
|
78
|
+
cf_name: el.title || el.ua || el.name,
|
79
|
+
cf_type: el.format || el.type,
|
80
|
+
cf_default: el.default,
|
81
|
+
cf_notnull: el.notnull,
|
82
|
+
object_id: table,
|
83
|
+
tablename: table,
|
84
|
+
};
|
85
|
+
|
86
|
+
data1.push({
|
87
|
+
name: obj.cf_id,
|
88
|
+
title: obj.cf_name,
|
89
|
+
format: obj.cf_type,
|
90
|
+
option: data[index]?.option,
|
91
|
+
hidden: data[index]?.hidden,
|
92
|
+
custom: true,
|
93
|
+
});
|
94
|
+
|
95
|
+
await dataInsert({
|
96
|
+
pg: client,
|
97
|
+
table: 'setting.custom_field',
|
98
|
+
data: obj,
|
99
|
+
uid,
|
100
|
+
});
|
101
|
+
}));
|
102
|
+
|
103
|
+
await client.query('delete from setting.custom_field where $1 in (tablename, object_id)', [table]);
|
104
|
+
await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
|
105
|
+
|
106
|
+
const data2 = JSON.stringify(data1?.filter((value, index, array) => array.indexOf(value) === index)); // ?.replace(/'+/g, "'")?.replace(/'/g, "''")
|
107
|
+
const res = await dataInsert({
|
108
|
+
pg: client,
|
109
|
+
table: 'setting.property',
|
110
|
+
data: {
|
111
|
+
property_entity: 'customColumn',
|
112
|
+
object_id: table,
|
113
|
+
property_json: data2,
|
114
|
+
},
|
115
|
+
uid,
|
116
|
+
});
|
117
|
+
Object.assign(result, res);
|
118
|
+
}
|
119
|
+
await client.query('COMMIT');
|
120
|
+
return prepareResult(result);
|
121
|
+
} catch (err) {
|
122
|
+
await client.query('ROLLBACK');
|
123
|
+
return { error: err.toString(), status: 500 };
|
124
|
+
}
|
125
|
+
finally {
|
126
|
+
client.release();
|
127
|
+
}
|
128
|
+
};
|
@@ -1,67 +1,67 @@
|
|
1
|
-
/* eslint-disable no-continue */
|
2
|
-
|
3
|
-
/**
|
4
|
-
* @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
|
5
|
-
* @param {String} opt.query - запит до таблиці
|
6
|
-
* @param {String} opt.hash - інформація з хешу по запиту
|
7
|
-
*/
|
8
|
-
|
9
|
-
import formatValue from './formatValue.js';
|
10
|
-
|
11
|
-
function getFilterQuery({ pg, filter: filterStr, fields, filterList }) {
|
12
|
-
if (!filterStr) return null; // filter list API
|
13
|
-
|
14
|
-
const mainOperators = ['=', '~', '>', '<'];
|
15
|
-
|
16
|
-
const filterQueryArray = decodeURIComponent(filterStr?.replace(/%/g, '%25').replace(/%/g, '\\%')?.replace(/(^,)|(,$)/g, '')).replace(/'/g, '').split(/[;|]/);
|
17
|
-
|
18
|
-
const resultList = [];
|
19
|
-
|
20
|
-
for (let i = 0; i < filterQueryArray.length; i += 1) {
|
21
|
-
const item = filterQueryArray[i];
|
22
|
-
const operator = mainOperators?.find((el) => item.indexOf(el) !== -1) || '=';
|
23
|
-
const [name] = item.split(operator);
|
24
|
-
|
25
|
-
// skip already added filter
|
26
|
-
if (resultList.find((el) => el.name === name)) {
|
27
|
-
continue;
|
28
|
-
}
|
29
|
-
|
30
|
-
// filter
|
31
|
-
const filter = filterList?.find((el) => [el.id, el.name].includes(name)) || { type: 'text' };
|
32
|
-
|
33
|
-
// find all value
|
34
|
-
const value = filterQueryArray.filter((el) => el.startsWith(name)).map((el) => el.substring(name.length + 1)).join(',');
|
35
|
-
|
36
|
-
if (filter?.query) {
|
37
|
-
resultList.push({
|
38
|
-
name, value, query: filter?.query, operator: '=', filterType: filter.type, type: 'text',
|
39
|
-
});
|
40
|
-
continue;
|
41
|
-
}
|
42
|
-
|
43
|
-
// find field and skip not exists
|
44
|
-
const { dataTypeID } = fields?.find((el) => el.name === name) || {};
|
45
|
-
|
46
|
-
// format query
|
47
|
-
const {
|
48
|
-
op, query, filterType, fieldType,
|
49
|
-
} = formatValue({
|
50
|
-
pg,
|
51
|
-
filter,
|
52
|
-
name,
|
53
|
-
value,
|
54
|
-
operator,
|
55
|
-
dataTypeID,
|
56
|
-
}) || {};
|
57
|
-
if (!query) continue;
|
58
|
-
|
59
|
-
resultList.push({
|
60
|
-
name, value, query, operator: op, filterType, type: fieldType,
|
61
|
-
});
|
62
|
-
}
|
63
|
-
|
64
|
-
return resultList;
|
65
|
-
}
|
66
|
-
|
67
|
-
export default getFilterQuery;
|
1
|
+
/* eslint-disable no-continue */
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
|
5
|
+
* @param {String} opt.query - запит до таблиці
|
6
|
+
* @param {String} opt.hash - інформація з хешу по запиту
|
7
|
+
*/
|
8
|
+
|
9
|
+
import formatValue from './formatValue.js';
|
10
|
+
|
11
|
+
function getFilterQuery({ pg, filter: filterStr, fields, filterList }) {
|
12
|
+
if (!filterStr) return null; // filter list API
|
13
|
+
|
14
|
+
const mainOperators = ['=', '~', '>', '<'];
|
15
|
+
|
16
|
+
const filterQueryArray = decodeURIComponent(filterStr?.replace(/%/g, '%25').replace(/%/g, '\\%')?.replace(/(^,)|(,$)/g, '')).replace(/'/g, '').split(/[;|]/);
|
17
|
+
|
18
|
+
const resultList = [];
|
19
|
+
|
20
|
+
for (let i = 0; i < filterQueryArray.length; i += 1) {
|
21
|
+
const item = filterQueryArray[i];
|
22
|
+
const operator = mainOperators?.find((el) => item.indexOf(el) !== -1) || '=';
|
23
|
+
const [name] = item.split(operator);
|
24
|
+
|
25
|
+
// skip already added filter
|
26
|
+
if (resultList.find((el) => el.name === name)) {
|
27
|
+
continue;
|
28
|
+
}
|
29
|
+
|
30
|
+
// filter
|
31
|
+
const filter = filterList?.find((el) => [el.id, el.name].includes(name)) || { type: 'text' };
|
32
|
+
|
33
|
+
// find all value
|
34
|
+
const value = filterQueryArray.filter((el) => el.startsWith(name)).map((el) => el.substring(name.length + 1)).join(',');
|
35
|
+
|
36
|
+
if (filter?.query) {
|
37
|
+
resultList.push({
|
38
|
+
name, value, query: filter?.query, operator: '=', filterType: filter.type, type: 'text',
|
39
|
+
});
|
40
|
+
continue;
|
41
|
+
}
|
42
|
+
|
43
|
+
// find field and skip not exists
|
44
|
+
const { dataTypeID } = fields?.find((el) => el.name === name) || {};
|
45
|
+
|
46
|
+
// format query
|
47
|
+
const {
|
48
|
+
op, query, filterType, fieldType,
|
49
|
+
} = formatValue({
|
50
|
+
pg,
|
51
|
+
filter,
|
52
|
+
name,
|
53
|
+
value,
|
54
|
+
operator,
|
55
|
+
dataTypeID,
|
56
|
+
}) || {};
|
57
|
+
if (!query) continue;
|
58
|
+
|
59
|
+
resultList.push({
|
60
|
+
name, value, query, operator: op, filterType, type: fieldType,
|
61
|
+
});
|
62
|
+
}
|
63
|
+
|
64
|
+
return resultList;
|
65
|
+
}
|
66
|
+
|
67
|
+
export default getFilterQuery;
|
@@ -1,16 +1,16 @@
|
|
1
|
-
import getTemplateApi from './controllers/getTemplate.js';
|
2
|
-
|
3
|
-
import getTemplateSchema from './schema.js'
|
4
|
-
|
5
|
-
export default async function route(fastify) {
|
6
|
-
//fastify.decorate('addTempateFolder', addTempateFolder); // call from funcs
|
7
|
-
fastify.get(`/template/:type/:name`, { config: { policy: ['public'] }, scheme: getTemplateSchema }, getTemplateApi);
|
8
|
-
|
9
|
-
/*fastify.addHook('onListen', async () => {
|
10
|
-
await addTempateFolder(path.join(process.cwd(), '/module/itree'));
|
11
|
-
await addTempateFolder(path.join(process.cwd(), '/module/test'));
|
12
|
-
});*/
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
1
|
+
import getTemplateApi from './controllers/getTemplate.js';
|
2
|
+
|
3
|
+
import getTemplateSchema from './schema.js'
|
4
|
+
|
5
|
+
export default async function route(fastify) {
|
6
|
+
//fastify.decorate('addTempateFolder', addTempateFolder); // call from funcs
|
7
|
+
fastify.get(`/template/:type/:name`, { config: { policy: ['public'] }, scheme: getTemplateSchema }, getTemplateApi);
|
8
|
+
|
9
|
+
/*fastify.addHook('onListen', async () => {
|
10
|
+
await addTempateFolder(path.join(process.cwd(), '/module/itree'));
|
11
|
+
await addTempateFolder(path.join(process.cwd(), '/module/test'));
|
12
|
+
});*/
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
}
|
@@ -1,54 +1,54 @@
|
|
1
|
-
import { pgClients } from "@opengis/fastify-table/utils.js";
|
2
|
-
|
3
|
-
export default async function userClsPost({
|
4
|
-
pg = pgClients.client, body = {}, user = {},
|
5
|
-
}) {
|
6
|
-
const { uid } = user || {};
|
7
|
-
const {
|
8
|
-
name, type = 'json', children = [], sql,
|
9
|
-
} = body;
|
10
|
-
|
11
|
-
if (!uid) {
|
12
|
-
return { message: 'access restricted', status: 403 };
|
13
|
-
}
|
14
|
-
|
15
|
-
if (!name) {
|
16
|
-
return { message: 'not enough params: name', status: 400 };
|
17
|
-
}
|
18
|
-
|
19
|
-
if (type === 'json' && (children?.length ? (!Array.isArray(children) || !children.length || !children?.[0]?.id) : false)) {
|
20
|
-
return { message: 'invalid params: children (array of objects)', status: 400 };
|
21
|
-
}
|
22
|
-
|
23
|
-
if (type === 'sql' && (!sql || typeof sql !== 'string')) {
|
24
|
-
return { message: 'invalid params: sql (string)', status: 400 };
|
25
|
-
}
|
26
|
-
|
27
|
-
|
28
|
-
const { rowCount = 0 } = await pg.query(`with recursive rows as (
|
29
|
-
select user_clsid, name, code, icon, color, parent
|
30
|
-
from admin.user_cls a
|
31
|
-
where name=$1
|
32
|
-
union all
|
33
|
-
select a.user_clsid, a.name, a.code, a.icon, a.color, a.parent
|
34
|
-
from admin.user_cls a
|
35
|
-
join rows b on a.parent=b.name
|
36
|
-
) delete from admin.user_cls where user_clsid in (select user_clsid from rows )`, [name]);
|
37
|
-
console.log('delete old user cls', name, rowCount);
|
38
|
-
|
39
|
-
const { id, data } = await pg.query('insert into admin.user_cls(name,type,data,uid) values($1,$2,$3,$4) returning user_clsid as id, data', [name, type, sql, uid])
|
40
|
-
.then((res) => res.rows?.[0] || {});
|
41
|
-
if (type === 'json' && children?.length) {
|
42
|
-
if (!id) { return { error: 'insert user cls error', status: 500 }; }
|
43
|
-
const q1 = `insert into admin.user_cls(code,name,color,icon,parent,uid)
|
44
|
-
|
45
|
-
select value->>'id',value->>'text',value->>'color',value->>'icon', '${name.replace(/'/g, "''")}', '${uid}'
|
46
|
-
from json_array_elements('${JSON.stringify(children).replace(/'/g, "''")}'::json)
|
47
|
-
|
48
|
-
returning user_clsid as id, code, name, parent`;
|
49
|
-
const { rows = [] } = await pg.query(q1);
|
50
|
-
return { id, name, type, children: rows };
|
51
|
-
}
|
52
|
-
return { id, name, type, data };
|
53
|
-
|
54
|
-
}
|
1
|
+
import { pgClients } from "@opengis/fastify-table/utils.js";
|
2
|
+
|
3
|
+
export default async function userClsPost({
|
4
|
+
pg = pgClients.client, body = {}, user = {},
|
5
|
+
}) {
|
6
|
+
const { uid } = user || {};
|
7
|
+
const {
|
8
|
+
name, type = 'json', children = [], sql,
|
9
|
+
} = body;
|
10
|
+
|
11
|
+
if (!uid) {
|
12
|
+
return { message: 'access restricted', status: 403 };
|
13
|
+
}
|
14
|
+
|
15
|
+
if (!name) {
|
16
|
+
return { message: 'not enough params: name', status: 400 };
|
17
|
+
}
|
18
|
+
|
19
|
+
if (type === 'json' && (children?.length ? (!Array.isArray(children) || !children.length || !children?.[0]?.id) : false)) {
|
20
|
+
return { message: 'invalid params: children (array of objects)', status: 400 };
|
21
|
+
}
|
22
|
+
|
23
|
+
if (type === 'sql' && (!sql || typeof sql !== 'string')) {
|
24
|
+
return { message: 'invalid params: sql (string)', status: 400 };
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
const { rowCount = 0 } = await pg.query(`with recursive rows as (
|
29
|
+
select user_clsid, name, code, icon, color, parent
|
30
|
+
from admin.user_cls a
|
31
|
+
where name=$1
|
32
|
+
union all
|
33
|
+
select a.user_clsid, a.name, a.code, a.icon, a.color, a.parent
|
34
|
+
from admin.user_cls a
|
35
|
+
join rows b on a.parent=b.name
|
36
|
+
) delete from admin.user_cls where user_clsid in (select user_clsid from rows )`, [name]);
|
37
|
+
console.log('delete old user cls', name, rowCount);
|
38
|
+
|
39
|
+
const { id, data } = await pg.query('insert into admin.user_cls(name,type,data,uid) values($1,$2,$3,$4) returning user_clsid as id, data', [name, type, sql, uid])
|
40
|
+
.then((res) => res.rows?.[0] || {});
|
41
|
+
if (type === 'json' && children?.length) {
|
42
|
+
if (!id) { return { error: 'insert user cls error', status: 500 }; }
|
43
|
+
const q1 = `insert into admin.user_cls(code,name,color,icon,parent,uid)
|
44
|
+
|
45
|
+
select value->>'id',value->>'text',value->>'color',value->>'icon', '${name.replace(/'/g, "''")}', '${uid}'
|
46
|
+
from json_array_elements('${JSON.stringify(children).replace(/'/g, "''")}'::json)
|
47
|
+
|
48
|
+
returning user_clsid as id, code, name, parent`;
|
49
|
+
const { rows = [] } = await pg.query(q1);
|
50
|
+
return { id, name, type, children: rows };
|
51
|
+
}
|
52
|
+
return { id, name, type, data };
|
53
|
+
|
54
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import codeGenerator from "./controllers/code.generator.js";
|
2
|
-
|
3
|
-
export default async function plugin(fastify, opts) {
|
4
|
-
fastify.get('/code-gen/:token/:column/:id?', { config: { policy: ['user'] } }, codeGenerator);
|
5
|
-
}
|
1
|
+
import codeGenerator from "./controllers/code.generator.js";
|
2
|
+
|
3
|
+
export default async function plugin(fastify, opts) {
|
4
|
+
fastify.get('/code-gen/:token/:column/:id?', { config: { policy: ['user'] } }, codeGenerator);
|
5
|
+
}
|