@opengis/admin 0.4.9 → 0.4.11
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/README.md +97 -97
- package/dist/{add-page-Cea2Zmef.js → add-page-Dr2puaaA.js} +1 -1
- package/dist/{admin-interface-Ds_NL2yu.js → admin-interface-DrOpA2in.js} +2 -2
- package/dist/{admin-view-D6Sb37ch.js → admin-view-CAeidCEb.js} +3 -3
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +74 -74
- package/dist/assets/logo.svg +41 -41
- package/dist/{card-view-D8dD3R4J.js → card-view-Xjfy9e67.js} +1 -1
- package/dist/{edit-page-BFAOXVk_.js → edit-page-BwLm4xql.js} +1 -1
- package/dist/{import-file-CpGcbXxn.js → import-file-DhiI6wfo.js} +11500 -11500
- package/dist/{profile-page-D91gUFht.js → profile-page-B9AsAneW.js} +1 -1
- package/dist/style.css +1 -1
- package/module/settings/card/admin.accounts.table/index.yml +7 -7
- package/module/settings/card/admin.accounts.table/rules.hbs +18 -18
- package/module/settings/card/admin.accounts.table/users.hbs +13 -13
- package/module/settings/card/admin.routes.table/groups.hbs +11 -11
- package/module/settings/card/admin.routes.table/users.hbs +16 -16
- package/module/settings/cls/core.actions.json +17 -17
- package/module/settings/cls/core.scope.json +13 -13
- package/module/settings/cls/properties.site_status.json +13 -13
- package/module/settings/cls/properties.widget_status.json +13 -13
- package/module/settings/cls/yes_no.json +11 -11
- package/module/settings/form/admin.accounts.form.json +13 -13
- package/module/settings/form/admin.properties.form.json +15 -15
- package/module/settings/form/admin.roles.form.json +21 -21
- package/module/settings/form/admin.user_properties.form.json +15 -15
- package/module/settings/form/admin.user_roles_card.form.json +13 -13
- package/module/settings/interface/admin.properties.json +4 -4
- package/module/settings/interface/admin.roles.json +4 -4
- package/module/settings/interface/admin.routes.json +4 -4
- package/module/settings/interface/admin.users.json +4 -4
- package/module/settings/select/core.routes.sql +1 -1
- package/module/settings/select/core.user_mentioned.sql +1 -1
- package/module/settings/select/core.user_uid.sql +1 -1
- package/module/settings/table/admin.properties.table.json +39 -39
- package/module/settings/table/admin.user_properties.table.json +34 -34
- package/package.json +3 -3
- package/plugin.js +1 -1
- package/server/helpers/core/coalesce.js +7 -7
- package/server/helpers/core/select.js +48 -48
- package/server/helpers/core/token.js +18 -18
- package/server/helpers/list/buttonHelper.js +21 -21
- package/server/helpers/list/utils/button.js +5 -5
- package/server/helpers/temp/contentList.js +58 -58
- package/server/helpers/temp/ifCond.js +101 -101
- package/server/helpers/utils/button.js +5 -5
- package/server/helpers/utils/mdToHTML.js +17 -17
- package/server/plugins/access/index.mjs +6 -6
- package/server/plugins/cron.js +10 -10
- package/server/plugins/docs.js +28 -28
- package/server/routes/access/controllers/access.group.js +29 -29
- package/server/routes/access/controllers/access.group.post.js +54 -54
- package/server/routes/access/index.mjs +11 -11
- package/server/routes/access/schema.mjs +67 -67
- package/server/routes/calendar/controllers/calendar.data.js +125 -125
- package/server/routes/calendar/index.mjs +7 -7
- package/server/routes/notifications/controllers/readNotifications.js +18 -18
- package/server/routes/notifications/controllers/testEmail.js +35 -35
- package/server/routes/notifications/controllers/userNotifications.js +53 -53
- package/server/routes/notifications/hook/onWidgetSet.js +56 -56
- package/server/routes/notifications/index.mjs +26 -26
- package/server/routes/root.mjs +3 -3
- package/server/routes/user/controllers/user.cls.id.js +14 -14
- package/server/routes/user/controllers/user.cls.js +72 -72
- package/server/routes/user/controllers/user.info.js +17 -17
- package/server/routes/util/controllers/code.generator.js +89 -89
- package/server/routes/widget/controllers/widget.del.js +79 -79
- package/server/routes/widget/controllers/widget.set.js +99 -99
- package/server/routes/widget/hook/onWidgetSet.js +12 -12
- package/server/routes/widget/index.mjs +20 -20
- package/server/routes/widget/schema.js +12 -12
- package/server/templates/cls/itree.recrzone_category.json +73 -73
- package/server/templates/cls/test.json +9 -9
- package/server/templates/form/admin.user_cls.data.form.json +49 -49
- package/server/templates/form/admin.user_group_rel.form.json +21 -21
- package/server/templates/form/form-user-pass.json +10 -10
- package/server/templates/form/form-user_group.json +39 -39
- package/server/templates/form/form-users.json +156 -156
- package/server/templates/form/user_group_access.form.json +22 -22
- package/server/templates/select/account_id.json +2 -2
- package/server/templates/table/gis.dataset.table.json +43 -43
- package/server/templates/table/management.user_group.table.json +112 -112
- package/server/templates/table/management.users.table.json +126 -126
- package/server/utils/addNotification.js +21 -21
- package/server/utils/sendNotification.js +89 -89
- package/server/routes/properties/controllers/admin.properties.get.js +0 -25
- package/server/routes/properties/controllers/admin.properties.post.js +0 -53
- package/server/routes/properties/controllers/table.properties.get.js +0 -120
- package/server/routes/properties/controllers/table.properties.post.js +0 -115
- package/server/routes/properties/controllers/user.properties.get.js +0 -19
- package/server/routes/properties/controllers/user.properties.post.js +0 -10
- package/server/routes/properties/index.mjs +0 -21
- package/server/routes/properties/schema.js +0 -11
- package/server/routes/properties/utils/dataInsert.js +0 -26
- package/server/routes/properties/utils/getColumnMetaData.js +0 -17
- package/server/routes/properties/utils/refreshData.js +0 -128
@@ -1,89 +1,89 @@
|
|
1
|
-
import { handlebars, pgClients, getTemplate, getRedis, logger } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
import sendEmail from './sendEmail.js';
|
4
|
-
|
5
|
-
// eslint-disable-next-line max-len, no-control-regex
|
6
|
-
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;
|
7
|
-
|
8
|
-
const rclient = getRedis();
|
9
|
-
|
10
|
-
async function generateNotificationContent({
|
11
|
-
pg, table, template, id, message, data: data1,
|
12
|
-
}) {
|
13
|
-
if (template) {
|
14
|
-
const data = table && id ? await pg.one(`select * from ${table} where ${pg.pk[table]}=$1`, [id]) : data1;
|
15
|
-
// console.log(data);
|
16
|
-
const body = await getTemplate('pt', template);
|
17
|
-
// console.log(body);
|
18
|
-
const html = handlebars.compile(body || template || 'template not found')(data || {});
|
19
|
-
// console.log(html);
|
20
|
-
return html;
|
21
|
-
}
|
22
|
-
return message;
|
23
|
-
}
|
24
|
-
|
25
|
-
// to do: refactor fastify-file to remove funcs completely
|
26
|
-
export default async function notification({
|
27
|
-
pg = pgClients.client,
|
28
|
-
provider = ['email'],
|
29
|
-
from,
|
30
|
-
to,
|
31
|
-
template,
|
32
|
-
table,
|
33
|
-
message,
|
34
|
-
title,
|
35
|
-
file,
|
36
|
-
data,
|
37
|
-
id,
|
38
|
-
nocache,
|
39
|
-
}) {
|
40
|
-
if (pg?.readonly) {
|
41
|
-
return null;
|
42
|
-
}
|
43
|
-
|
44
|
-
const keyTo = `${pg.options?.database}:mail:${provider[0]}:${to || ''}${id || ''}${table || ''}${title || ''}`;
|
45
|
-
const uniqueTo = await rclient.setnx(keyTo, 1);
|
46
|
-
|
47
|
-
if (!uniqueTo && !nocache) {
|
48
|
-
logger.file('notification/sent', { keyTo, send: uniqueTo, nocache });
|
49
|
-
return `already sent: ${keyTo}`;
|
50
|
-
}
|
51
|
-
await rclient.expire(keyTo, 1000 * 600);
|
52
|
-
|
53
|
-
if (!to.length) {
|
54
|
-
return null;
|
55
|
-
}
|
56
|
-
|
57
|
-
if (!(Array.isArray(provider) && provider.length)) {
|
58
|
-
return 'notification provider - must be array and not empty';
|
59
|
-
}
|
60
|
-
|
61
|
-
const html = await generateNotificationContent({
|
62
|
-
pg, table, template, id, message, data,
|
63
|
-
});
|
64
|
-
|
65
|
-
if (provider.includes('email')) {
|
66
|
-
const files = Array.isArray(file) ? file : [file];
|
67
|
-
const attachments = files?.length && false ? await Promise.all(files?.filter((el) => el).map(async (el) => {
|
68
|
-
/* const content = await downloadFile(el, { buffer: true }); // ?
|
69
|
-
return {
|
70
|
-
filename: el.split('/').pop(),
|
71
|
-
encoding: 'base64',
|
72
|
-
content,
|
73
|
-
}; */
|
74
|
-
})) : [];
|
75
|
-
|
76
|
-
const toEmail = Array.isArray(to) ? to.map((emails) => emails.match(emailReg)?.join(',')) : to;
|
77
|
-
|
78
|
-
const result = await sendEmail({
|
79
|
-
attachments,
|
80
|
-
html,
|
81
|
-
subject: title,
|
82
|
-
from,
|
83
|
-
to: toEmail,
|
84
|
-
});
|
85
|
-
|
86
|
-
return result;
|
87
|
-
}
|
88
|
-
return null;
|
89
|
-
}
|
1
|
+
import { handlebars, pgClients, getTemplate, getRedis, logger } from '@opengis/fastify-table/utils.js';
|
2
|
+
|
3
|
+
import sendEmail from './sendEmail.js';
|
4
|
+
|
5
|
+
// eslint-disable-next-line max-len, no-control-regex
|
6
|
+
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;
|
7
|
+
|
8
|
+
const rclient = getRedis();
|
9
|
+
|
10
|
+
async function generateNotificationContent({
|
11
|
+
pg, table, template, id, message, data: data1,
|
12
|
+
}) {
|
13
|
+
if (template) {
|
14
|
+
const data = table && id ? await pg.one(`select * from ${table} where ${pg.pk[table]}=$1`, [id]) : data1;
|
15
|
+
// console.log(data);
|
16
|
+
const body = await getTemplate('pt', template);
|
17
|
+
// console.log(body);
|
18
|
+
const html = handlebars.compile(body || template || 'template not found')(data || {});
|
19
|
+
// console.log(html);
|
20
|
+
return html;
|
21
|
+
}
|
22
|
+
return message;
|
23
|
+
}
|
24
|
+
|
25
|
+
// to do: refactor fastify-file to remove funcs completely
|
26
|
+
export default async function notification({
|
27
|
+
pg = pgClients.client,
|
28
|
+
provider = ['email'],
|
29
|
+
from,
|
30
|
+
to,
|
31
|
+
template,
|
32
|
+
table,
|
33
|
+
message,
|
34
|
+
title,
|
35
|
+
file,
|
36
|
+
data,
|
37
|
+
id,
|
38
|
+
nocache,
|
39
|
+
}) {
|
40
|
+
if (pg?.readonly) {
|
41
|
+
return null;
|
42
|
+
}
|
43
|
+
|
44
|
+
const keyTo = `${pg.options?.database}:mail:${provider[0]}:${to || ''}${id || ''}${table || ''}${title || ''}`;
|
45
|
+
const uniqueTo = await rclient.setnx(keyTo, 1);
|
46
|
+
|
47
|
+
if (!uniqueTo && !nocache) {
|
48
|
+
logger.file('notification/sent', { keyTo, send: uniqueTo, nocache });
|
49
|
+
return `already sent: ${keyTo}`;
|
50
|
+
}
|
51
|
+
await rclient.expire(keyTo, 1000 * 600);
|
52
|
+
|
53
|
+
if (!to.length) {
|
54
|
+
return null;
|
55
|
+
}
|
56
|
+
|
57
|
+
if (!(Array.isArray(provider) && provider.length)) {
|
58
|
+
return 'notification provider - must be array and not empty';
|
59
|
+
}
|
60
|
+
|
61
|
+
const html = await generateNotificationContent({
|
62
|
+
pg, table, template, id, message, data,
|
63
|
+
});
|
64
|
+
|
65
|
+
if (provider.includes('email')) {
|
66
|
+
const files = Array.isArray(file) ? file : [file];
|
67
|
+
const attachments = files?.length && false ? await Promise.all(files?.filter((el) => el).map(async (el) => {
|
68
|
+
/* const content = await downloadFile(el, { buffer: true }); // ?
|
69
|
+
return {
|
70
|
+
filename: el.split('/').pop(),
|
71
|
+
encoding: 'base64',
|
72
|
+
content,
|
73
|
+
}; */
|
74
|
+
})) : [];
|
75
|
+
|
76
|
+
const toEmail = Array.isArray(to) ? to.map((emails) => emails.match(emailReg)?.join(',')) : to;
|
77
|
+
|
78
|
+
const result = await sendEmail({
|
79
|
+
attachments,
|
80
|
+
html,
|
81
|
+
subject: title,
|
82
|
+
from,
|
83
|
+
to: toEmail,
|
84
|
+
});
|
85
|
+
|
86
|
+
return result;
|
87
|
+
}
|
88
|
+
return null;
|
89
|
+
}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
const table = 'admin.properties';
|
2
|
-
|
3
|
-
import { pgClients, getTemplatePath, getTemplate } from '@opengis/fastify-table/utils.js';
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
export default async function getSettingsApp({
|
8
|
-
pg = pgClients.client,
|
9
|
-
}, reply) {
|
10
|
-
const time = Date.now();
|
11
|
-
|
12
|
-
if (!pg.pk?.[table]) {
|
13
|
-
return reply.status(404).send('table not found');
|
14
|
-
}
|
15
|
-
|
16
|
-
const { rows = [] } = await pg.query('select property_key as key, property_text, property_json from admin.properties');
|
17
|
-
|
18
|
-
const settings = rows.reduce((acc, { key, property_text, property_json }) => ({ ...acc, [key]: property_text || property_json }), {});
|
19
|
-
|
20
|
-
const forms = await Promise.all(getTemplatePath('setting')
|
21
|
-
.map(async (el) => ({ name: el[0], body: await getTemplate('setting', el[0]) }))
|
22
|
-
);
|
23
|
-
|
24
|
-
return reply.status(200).send({ time: Date.now() - time, forms, settings });
|
25
|
-
}
|
@@ -1,53 +0,0 @@
|
|
1
|
-
const table = 'admin.properties';
|
2
|
-
|
3
|
-
import { dataInsert, pgClients } from '@opengis/fastify-table/utils.js';
|
4
|
-
|
5
|
-
function checkValueType(val) {
|
6
|
-
if (val) {
|
7
|
-
if (typeof val === 'object') {
|
8
|
-
return 'property_json';
|
9
|
-
}
|
10
|
-
if (typeof val === 'number' && (!/\D/.test(val.toString()) && val.toString().length < 10)) {
|
11
|
-
return 'property_int';
|
12
|
-
}
|
13
|
-
}
|
14
|
-
return 'property_text';
|
15
|
-
}
|
16
|
-
|
17
|
-
export default async function postSettingsApp({
|
18
|
-
pg = pgClients.client, body = {}, user = {}, uid = user?.uid,
|
19
|
-
}, reply) {
|
20
|
-
if (!user?.user_type?.includes?.('admin')) {
|
21
|
-
return reply.status(403).send('access restricted');
|
22
|
-
}
|
23
|
-
const { key, val } = body;
|
24
|
-
|
25
|
-
if ((!key || !val) && !Object.keys(body).length) {
|
26
|
-
return reply.status(400).send('not enough body params');
|
27
|
-
}
|
28
|
-
|
29
|
-
if (!pg?.pk?.[table]) {
|
30
|
-
return reply.status(404).send('table not found');
|
31
|
-
}
|
32
|
-
|
33
|
-
const keys = Object.keys(body);
|
34
|
-
await pg.query(`delete from ${table} where property_key=any($1)`, [keys]);
|
35
|
-
|
36
|
-
await Promise.all(keys.filter(el => body[el]).map(async (el) => {
|
37
|
-
const columnType = table === 'admin.user_properties'
|
38
|
-
? 'property_json'
|
39
|
-
: checkValueType(body[el]);
|
40
|
-
|
41
|
-
await dataInsert({
|
42
|
-
pg,
|
43
|
-
table,
|
44
|
-
data: { property_key: el, [columnType]: body[el] },
|
45
|
-
uid,
|
46
|
-
});
|
47
|
-
|
48
|
-
}));
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
return { message: 'ok', status: 200 };
|
53
|
-
}
|
@@ -1,120 +0,0 @@
|
|
1
|
-
import { pgClients, getMeta, getTemplate } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
import getColumnMetaData from '../utils/getColumnMetaData.js';
|
4
|
-
|
5
|
-
/**
|
6
|
-
*
|
7
|
-
* @method GET
|
8
|
-
* @priority 4
|
9
|
-
* @alias getSettingsTable
|
10
|
-
* @type api
|
11
|
-
* @tag custom
|
12
|
-
|
13
|
-
* @returns {String} message and status
|
14
|
-
*/
|
15
|
-
|
16
|
-
export default async function getSettingsTable({
|
17
|
-
pg = pgClients.client, params = {}, user = {}, query = {},
|
18
|
-
}) {
|
19
|
-
const { table, entity } = params;
|
20
|
-
const { uid } = user;
|
21
|
-
const time = [];
|
22
|
-
|
23
|
-
if (!uid) {
|
24
|
-
return { message: 'access restricted', status: 401 };
|
25
|
-
}
|
26
|
-
|
27
|
-
if (!table) {
|
28
|
-
return { message: 'not enough params: table', status: 400 };
|
29
|
-
}
|
30
|
-
|
31
|
-
const loadTable = await getTemplate('table', table);
|
32
|
-
|
33
|
-
const tableName = loadTable?.table || table;
|
34
|
-
const meta = await getMeta({ pg, table: tableName });
|
35
|
-
const { view, pk } = meta || {};
|
36
|
-
time.push(Date.now());
|
37
|
-
|
38
|
-
if (!pk && !view) {
|
39
|
-
return {
|
40
|
-
message: `table primary key not found: ${tableName}`,
|
41
|
-
status: 400,
|
42
|
-
};
|
43
|
-
}
|
44
|
-
|
45
|
-
const { rows: geometry } = meta?.geom
|
46
|
-
? await pg.queryCache(`select st_geometrytype(${meta?.geom}) as type ,count(*)
|
47
|
-
from ${tableName} group by st_geometrytype(${meta?.geom})`, { table: tableName }) : [];
|
48
|
-
time.push(Date.now());
|
49
|
-
|
50
|
-
const stat = !view ? await getColumnMetaData({ pg, table: tableName }) : {};
|
51
|
-
time.push(Date.now());
|
52
|
-
|
53
|
-
const { total = 0 } = await pg.queryCache(`select count(*) as total from ${tableName}`, { table: tableName })
|
54
|
-
.then(el => el.rows?.[0] || {});
|
55
|
-
time.push(Date.now());
|
56
|
-
|
57
|
-
const { property_json: customColumns = [] } = await pg.query(`select property_json::json from setting.property
|
58
|
-
where property_entity='customColumn' and object_id=$1`, [table]).then(el => el.rows?.[0] || {});
|
59
|
-
|
60
|
-
const { property_json: tableSettingColumns } = await pg.query(`select property_json::json from setting.property
|
61
|
-
where property_entity='column' and object_id=$1`, [table]).then(el => el.rows?.[0] || {});
|
62
|
-
|
63
|
-
const columns = (tableSettingColumns || loadTable?.columns || meta?.columns)?.map((el) => ({ ...el, title: el.title || el.name }))
|
64
|
-
?.filter((value, index, array) => array?.map((el) => el.name).indexOf(value.name) === index); // get unique columns
|
65
|
-
|
66
|
-
const cls = columns?.filter((el) => ['badge', 'select'].includes(el.format) && (el.option || el.data))
|
67
|
-
?.map((el) => (el.option || el.data))
|
68
|
-
?.filter((value, index, array) => array.indexOf(value) === index); // get unique cls
|
69
|
-
|
70
|
-
const { property_json: userFilterList } = await pg.query(`select property_json::json from setting.property
|
71
|
-
where property_entity='filter' and object_id=$1`, [table]).then(el => el.rows?.[0] || {});
|
72
|
-
|
73
|
-
const { property_json: customQuery } = await pg.query(`select json_agg(json_build_object('id',property_id,'name', property_key,
|
74
|
-
'query', property_text, 'disabled', coalesce((property_json::json->>'disabled')::boolean,false) )) as property_json
|
75
|
-
from setting.property where 1=1 and property_entity='customQuery' and object_id=$1`, [table]).then(el => el.rows?.[0] || {});
|
76
|
-
|
77
|
-
time.push(Date.now());
|
78
|
-
|
79
|
-
const debug = user?.user_type?.includes('admin') && query?.debug
|
80
|
-
? {
|
81
|
-
view,
|
82
|
-
tableName,
|
83
|
-
opt,
|
84
|
-
colModel,
|
85
|
-
metaColumns: meta?.columns,
|
86
|
-
columnProperties: tableSettingColumns,
|
87
|
-
}
|
88
|
-
: undefined;
|
89
|
-
|
90
|
-
const res = {
|
91
|
-
message: {
|
92
|
-
time: {
|
93
|
-
geom: time[1] - time[0],
|
94
|
-
stat: time[2] - time[1],
|
95
|
-
count: time[3] - time[2],
|
96
|
-
total: time[4] - time[0],
|
97
|
-
},
|
98
|
-
debug,
|
99
|
-
model: tableName,
|
100
|
-
total,
|
101
|
-
geometry,
|
102
|
-
stat,
|
103
|
-
cls,
|
104
|
-
columns,
|
105
|
-
filters: userFilterList?.length
|
106
|
-
? userFilterList
|
107
|
-
: loadTable?.filters?.map((el) => ({ ...el, title: el.title || el.ua })),
|
108
|
-
customQuery: customQuery?.length ? customQuery : [],
|
109
|
-
customColumns,
|
110
|
-
customFilters: userFilterList || [],
|
111
|
-
},
|
112
|
-
status: 200,
|
113
|
-
};
|
114
|
-
|
115
|
-
if (entity) {
|
116
|
-
return { [entity]: res.message[entity] };
|
117
|
-
}
|
118
|
-
|
119
|
-
return res;
|
120
|
-
};
|
@@ -1,115 +0,0 @@
|
|
1
|
-
import { getRedis, pgClients } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
import refreshData from '../utils/refreshData.js';
|
4
|
-
|
5
|
-
const rclient = getRedis();
|
6
|
-
|
7
|
-
/**
|
8
|
-
*
|
9
|
-
* @method POST
|
10
|
-
* @priority 4
|
11
|
-
* @alias postSettingsTable
|
12
|
-
* @type api
|
13
|
-
* @tag custom
|
14
|
-
* @returns {String} message and status
|
15
|
-
*/
|
16
|
-
|
17
|
-
export default async function postTablpostSettingsTableeProperties({
|
18
|
-
pg = pgClients.client, params = {}, body = {}, user = {},
|
19
|
-
}) {
|
20
|
-
const { table } = params;
|
21
|
-
const { uid } = user;
|
22
|
-
|
23
|
-
if (!uid) {
|
24
|
-
return { message: 'access restricted', status: 401 };
|
25
|
-
}
|
26
|
-
|
27
|
-
if (!table) {
|
28
|
-
return { message: 'not enough params: table', status: 400 };
|
29
|
-
}
|
30
|
-
|
31
|
-
const {
|
32
|
-
deleted = [],
|
33
|
-
columns = [],
|
34
|
-
filters = [],
|
35
|
-
customColumns = [],
|
36
|
-
customQuery = [],
|
37
|
-
} = body;
|
38
|
-
|
39
|
-
const cacheKey = `${pg.options?.database}:filter-list:${table}`;
|
40
|
-
|
41
|
-
if (Array.isArray(deleted) && deleted?.length) {
|
42
|
-
const sqlList = {
|
43
|
-
columns: `delete from setting.property where property_entity='column' and object_id=$1`,
|
44
|
-
filters: `delete from setting.property where property_entity='filter' and object_id=$1`,
|
45
|
-
customColumns: `delete from setting.custom_data where attr in (select cf_id from setting.custom_field where object_id=$1);
|
46
|
-
delete from setting.custom_field where object_id=$1;
|
47
|
-
delete from setting.property where property_entity='customColumn' and object_id=$1;`,
|
48
|
-
customQuery: `delete from setting.property where property_entity='customQuery' and object_id=$1;`,
|
49
|
-
};
|
50
|
-
const q = deleted.map((item) => sqlList[item])?.filter((el) => el)?.join(' ');
|
51
|
-
const { rowCount = 0 } = await pg.query(q, [table]);
|
52
|
-
|
53
|
-
if (['customColumn', 'column'].find((el) => deleted.includes(el))) {
|
54
|
-
// await funcs.applyHook('preTemplate', { pg, name: table, type: 'table' });
|
55
|
-
}
|
56
|
-
if (['customQuery', 'filter'].find((el) => deleted.includes(el))) {
|
57
|
-
await rclient.del(cacheKey);
|
58
|
-
}
|
59
|
-
|
60
|
-
if (rowCount === 0) {
|
61
|
-
return { message: 'nothing to restore', status: 200 };
|
62
|
-
}
|
63
|
-
|
64
|
-
return {
|
65
|
-
message: {
|
66
|
-
command: 'DELETE',
|
67
|
-
deleted,
|
68
|
-
table,
|
69
|
-
result: 'success',
|
70
|
-
},
|
71
|
-
status: 200,
|
72
|
-
};
|
73
|
-
}
|
74
|
-
|
75
|
-
const result = {};
|
76
|
-
// custom filter query (sql)
|
77
|
-
if (customQuery?.length) {
|
78
|
-
const res = await refreshData({ pg, entity: 'customQuery', table, uid, data: customQuery });
|
79
|
-
if (res?.error) return res;
|
80
|
-
Object.assign(result, { customQuery: res });
|
81
|
-
}
|
82
|
-
|
83
|
-
// columns
|
84
|
-
if (columns?.length) {
|
85
|
-
const res = await refreshData({ pg, entity: 'column', table, uid, data: columns });
|
86
|
-
if (res?.error) return res;
|
87
|
-
Object.assign(result, { columns: res });
|
88
|
-
}
|
89
|
-
|
90
|
-
// custom columns
|
91
|
-
if (customColumns?.length) {
|
92
|
-
const colModel = await pg.query(`select property_json::json from setting.property
|
93
|
-
where property_entity='customColumn' and object_id=$1`, [table]).then((el) => el.rows?.[0]?.property_json);
|
94
|
-
|
95
|
-
const res = await refreshData({ pg, entity: 'customColumn', table, uid, data: customColumns, colModel });
|
96
|
-
if (res?.error) return res;
|
97
|
-
Object.assign(result, { customColumns: res });
|
98
|
-
}
|
99
|
-
|
100
|
-
// filters
|
101
|
-
if (filters?.length) {
|
102
|
-
const res = await refreshData({ pg, entity: 'filter', table, uid, data: filters });
|
103
|
-
if (res?.error) return res;
|
104
|
-
Object.assign(result, { filters: res });
|
105
|
-
}
|
106
|
-
|
107
|
-
if (columns?.length || customColumns?.length) {
|
108
|
-
// await funcs.applyHook('preTemplate', { pg, type: 'table', name: table });
|
109
|
-
}
|
110
|
-
if (filters?.length || customQuery?.length) {
|
111
|
-
await rclient.del(cacheKey);
|
112
|
-
}
|
113
|
-
|
114
|
-
return { message: result, status: 200 };
|
115
|
-
};
|
@@ -1,19 +0,0 @@
|
|
1
|
-
const table = 'admin.user_properties';
|
2
|
-
|
3
|
-
|
4
|
-
export default async function getSettingsUser({
|
5
|
-
pg = {}, session = {},
|
6
|
-
}) {
|
7
|
-
const { uid } = session.passport?.user || {};
|
8
|
-
if (!uid) {
|
9
|
-
return { message: 'access restreicted', status: 403 };
|
10
|
-
}
|
11
|
-
|
12
|
-
if (!pg.pk?.[table]) {
|
13
|
-
return { message: 'table not found', status: 404 };
|
14
|
-
}
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
return { message: 'user', status: 200 };
|
19
|
-
}
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import getSettingsApp from './controllers/admin.properties.get.js';
|
2
|
-
import postSettingsApp from './controllers/admin.properties.post.js';
|
3
|
-
|
4
|
-
//import getSettingsUser from './controllers/user.properties.get.js';
|
5
|
-
//import postSettingsUser from './controllers/user.properties.post.js';
|
6
|
-
|
7
|
-
import getSettingsTable from './controllers/table.properties.get.js';
|
8
|
-
import postSettingsTable from './controllers/table.properties.post.js';
|
9
|
-
|
10
|
-
import { propertiesSchema } from './schema.js';
|
11
|
-
|
12
|
-
export default async function route(fastify) {
|
13
|
-
fastify.get('/settings-app/:key?', { scheme: propertiesSchema }, getSettingsApp);
|
14
|
-
fastify.post('/settings-app', { config: { policy: ['admin'] } }, postSettingsApp);
|
15
|
-
|
16
|
-
//fastify.get('/settings-user/:key?', { scheme: propertiesSchema }, getSettingsUser);
|
17
|
-
// fastify.post('/settings-user', {}, postSettingsUser);
|
18
|
-
|
19
|
-
fastify.get('/settings-table/:table/:entity?', {}, getSettingsTable);
|
20
|
-
fastify.post('/settings-table/:table', {}, postSettingsTable);
|
21
|
-
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { getMeta, getPG } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
export default async function dataInsert({
|
4
|
-
table, data, pg: pg1,
|
5
|
-
}) {
|
6
|
-
const pg = pg1 || getPG({ name: 'client' });
|
7
|
-
if (!data) return null;
|
8
|
-
const { columns } = await getMeta(table);
|
9
|
-
if (!columns) return null;
|
10
|
-
|
11
|
-
const names = columns.map((el) => el.name);
|
12
|
-
const filterData = Object.keys(data)
|
13
|
-
.filter((el) => data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
14
|
-
|
15
|
-
const insertQuery = `insert into ${table}
|
16
|
-
|
17
|
-
( ${filterData?.map((key) => `"${key[0]}"`).join(',')})
|
18
|
-
|
19
|
-
values (${filterData?.map((key, i) => (key[0] === 'property_json' ? `to_json($${i + 1}::${key[1] && typeof key[1] === 'object' ? 'json' : 'text'})` : `$${i + 1}`)).join(',')})
|
20
|
-
|
21
|
-
returning *`;
|
22
|
-
|
23
|
-
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
|
24
|
-
|
25
|
-
return res;
|
26
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { pgClients, getMeta } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
export default async function getColumnMetaData({
|
4
|
-
pg = pgClients.client, table,
|
5
|
-
}) {
|
6
|
-
if (!table) return null;
|
7
|
-
|
8
|
-
const { columns = [] } = await getMeta({ pg, table });
|
9
|
-
const columnList = columns.filter(el => !['files', 'uid', 'editor_date', 'editor_id', 'cdate'].includes(el.name)).map(el => el.name);
|
10
|
-
|
11
|
-
const sql = `select count(*) as total, ${columnList.map((item) => `(count(*) filter(where ${item} is not null)) as "${item}"`).join(',')} from ${table}`;
|
12
|
-
const res = await pg.queryCache(sql, { table }).then(el => el.rows?.[0] || {});
|
13
|
-
|
14
|
-
return columns
|
15
|
-
.filter(el => !['files', 'uid', 'editor_date', 'editor_id', 'cdate'].includes(el.name))
|
16
|
-
.map((row) => Object.assign(row, { percent: ((+res[row.name] / +res.total) * 100).toFixed(0) }));
|
17
|
-
};
|