@opengis/admin 0.4.15 → 0.4.16

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.
Files changed (86) hide show
  1. package/README.md +97 -97
  2. package/dist/{add-page-CLQKORAq.js → add-page-CuSnPcPi.js} +1 -1
  3. package/dist/{admin-interface-CpLDRPag.js → admin-interface-D-iedgAS.js} +2 -2
  4. package/dist/{admin-view-B2qQ1IHJ.js → admin-view-BFLFL7ja.js} +1 -1
  5. package/dist/admin.js +1 -1
  6. package/dist/admin.umd.cjs +1 -1
  7. package/dist/assets/logo.svg +41 -41
  8. package/dist/{card-view-Cj5WEg5z.js → card-view-qp3cCQHr.js} +1 -1
  9. package/dist/{edit-page-r6I6Vi6E.js → edit-page-YQeMJOYf.js} +1 -1
  10. package/dist/{import-file-q1gVGP28.js → import-file-EI9a0fXk.js} +7 -7
  11. package/dist/{profile-page-DRdrE5zR.js → profile-page-7PoRBdwC.js} +1 -1
  12. package/dist/style.css +1 -1
  13. package/module/settings/card/admin.accounts.table/index.yml +7 -7
  14. package/module/settings/card/admin.accounts.table/rules.hbs +18 -18
  15. package/module/settings/card/admin.accounts.table/users.hbs +13 -13
  16. package/module/settings/card/admin.routes.table/groups.hbs +11 -11
  17. package/module/settings/card/admin.routes.table/users.hbs +16 -16
  18. package/module/settings/cls/core.actions.json +17 -17
  19. package/module/settings/cls/core.scope.json +13 -13
  20. package/module/settings/cls/properties.site_status.json +13 -13
  21. package/module/settings/cls/properties.widget_status.json +13 -13
  22. package/module/settings/cls/yes_no.json +11 -11
  23. package/module/settings/form/admin.accounts.form.json +13 -13
  24. package/module/settings/form/admin.properties.form.json +15 -15
  25. package/module/settings/form/admin.roles.form.json +21 -21
  26. package/module/settings/form/admin.user_properties.form.json +15 -15
  27. package/module/settings/form/admin.user_roles_card.form.json +13 -13
  28. package/module/settings/interface/admin.properties.json +4 -4
  29. package/module/settings/interface/admin.roles.json +4 -4
  30. package/module/settings/interface/admin.routes.json +4 -4
  31. package/module/settings/interface/admin.users.json +4 -4
  32. package/module/settings/select/core.routes.sql +1 -1
  33. package/module/settings/select/core.user_mentioned.sql +1 -1
  34. package/module/settings/select/core.user_uid.sql +1 -1
  35. package/module/settings/table/admin.properties.table.json +39 -39
  36. package/module/settings/table/admin.user_properties.table.json +34 -34
  37. package/package.json +2 -2
  38. package/server/helpers/core/coalesce.js +7 -7
  39. package/server/helpers/core/select.js +48 -48
  40. package/server/helpers/core/token.js +18 -18
  41. package/server/helpers/list/buttonHelper.js +21 -21
  42. package/server/helpers/list/utils/button.js +5 -5
  43. package/server/helpers/temp/contentList.js +58 -58
  44. package/server/helpers/temp/ifCond.js +101 -101
  45. package/server/helpers/utils/button.js +5 -5
  46. package/server/helpers/utils/mdToHTML.js +17 -17
  47. package/server/plugins/access/index.mjs +6 -6
  48. package/server/plugins/cron.js +10 -10
  49. package/server/plugins/docs.js +28 -28
  50. package/server/routes/access/controllers/access.group.js +29 -29
  51. package/server/routes/access/controllers/access.group.post.js +54 -54
  52. package/server/routes/access/index.mjs +11 -11
  53. package/server/routes/access/schema.mjs +67 -67
  54. package/server/routes/calendar/controllers/calendar.data.js +125 -125
  55. package/server/routes/calendar/index.mjs +7 -7
  56. package/server/routes/notifications/controllers/readNotifications.js +18 -18
  57. package/server/routes/notifications/controllers/testEmail.js +35 -35
  58. package/server/routes/notifications/controllers/userNotifications.js +53 -53
  59. package/server/routes/notifications/hook/onWidgetSet.js +56 -56
  60. package/server/routes/notifications/index.mjs +26 -26
  61. package/server/routes/root.mjs +3 -3
  62. package/server/routes/user/controllers/user.cls.id.js +14 -14
  63. package/server/routes/user/controllers/user.cls.js +72 -72
  64. package/server/routes/user/controllers/user.info.js +17 -17
  65. package/server/routes/util/controllers/code.generator.js +89 -89
  66. package/server/templates/cls/itree.recrzone_category.json +73 -73
  67. package/server/templates/cls/test.json +9 -9
  68. package/server/templates/form/admin.user_cls.data.form.json +49 -49
  69. package/server/templates/form/admin.user_group_rel.form.json +21 -21
  70. package/server/templates/form/form-user-pass.json +10 -10
  71. package/server/templates/form/form-user_group.json +39 -39
  72. package/server/templates/form/form-users.json +156 -156
  73. package/server/templates/form/user_group_access.form.json +22 -22
  74. package/server/templates/select/account_id.json +2 -2
  75. package/server/templates/table/gis.dataset.table.json +43 -43
  76. package/server/templates/table/management.user_group.table.json +112 -112
  77. package/server/templates/table/management.users.table.json +126 -126
  78. package/server/utils/addNotification.js +21 -21
  79. package/server/utils/sendNotification.js +89 -89
  80. package/server/routes/widget/controllers/file.edit.js +0 -51
  81. package/server/routes/widget/controllers/widget.del.js +0 -79
  82. package/server/routes/widget/controllers/widget.get.js +0 -136
  83. package/server/routes/widget/controllers/widget.set.js +0 -99
  84. package/server/routes/widget/hook/onWidgetSet.js +0 -12
  85. package/server/routes/widget/index.mjs +0 -20
  86. package/server/routes/widget/schema.js +0 -13
@@ -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,51 +0,0 @@
1
- import path from 'node:path';
2
-
3
- import { dataUpdate, pgClients, uploadMultiPart } from '@opengis/fastify-table/utils.js';
4
-
5
- export default async function widgetSet(req, reply) {
6
- const { pg = pgClients.client, headers = {}, user = {}, params = {} } = req;
7
-
8
- if (!params?.id) {
9
- return reply.status(400).send('not enough params: id');
10
- }
11
-
12
- if (!pg.pk?.['crm.files']) {
13
- return reply.status(404).send('table not found');
14
- }
15
-
16
- if (headers['content-type']?.split?.(';')?.shift?.() !== 'multipart/form-data') {
17
- return reply.status(400).send('invalid payload content type');
18
- }
19
-
20
- const file = await uploadMultiPart(req);
21
- const extName = path.extname(file.filepath).slice(1).toLowerCase();
22
-
23
- const data = {
24
- uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
25
- file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
26
- ext: extName,
27
- size: file?.size,
28
- file_status: 1,
29
- uid: user?.uid || 1,
30
- };
31
-
32
- const result = await dataUpdate({
33
- pg,
34
- table: 'crm.files',
35
- id: params.id,
36
- data,
37
- uid: user?.uid,
38
- });
39
-
40
- if (!result?.file_id) {
41
- return reply.status(404).send('file not found');
42
- }
43
-
44
- return reply.status(200).send({
45
- rowCount: 1,
46
- data: result,
47
- command: 'UPLOAD',
48
- id: result?.file_id,
49
- entity_id: result?.entity_id,
50
- });
51
- }
@@ -1,79 +0,0 @@
1
- import { pgClients, logChanges, isFileExists } from "@opengis/fastify-table/utils.js";
2
-
3
- import { isAdmin } from "../../../../utils.js";
4
-
5
- async function checkAccess(pg, objectid, id) {
6
- const { uid, filepath } = await pg.query(`select uid, file_path as filepath from crm.files where entity_id=$1 and file_id=$2`, [objectid, id])
7
- .then(el => el.rows?.[0] || {});
8
- return { uid, exists: filepath ? await isFileExists(filepath) : null };
9
- }
10
-
11
- /**
12
- * Дістає CRM дані для vue хешує ідентифікатори, підтягує селекти
13
- *
14
- * @method DELETE
15
- * @summary CRM дані для обраного віджета.
16
- * @priority 2
17
- * @tag table
18
- * @type api
19
- * @requires setTokenById
20
- * @requires getSelect
21
- * @param {String} id Ідентифікатор для хешування
22
- * @param {Any} sql Використовується для повернення sql запиту
23
- * @param {String} type Тип для хешування даних
24
- * @errors 400, 500
25
- * @returns {Number} status Номер помилки
26
- * @returns {String|Object} error Опис помилки
27
- * @returns {String|Object} message Повідомлення про успішне виконання або об'єкт з параметрами
28
- */
29
-
30
- export default async function widgetDel(req, reply) {
31
- const {
32
- pg = pgClients.client, params = {}, user = {},
33
- } = req;
34
-
35
- if (!user?.uid) {
36
- return reply.status(401).send('access restricted: user not authorized');
37
- }
38
-
39
- const { type, objectid, id } = params;
40
-
41
- if (!objectid) {
42
- return reply.status(400).send('not enough params: id');
43
- }
44
-
45
- // force delete db entry if file not exists
46
- const { exists, uid } = ['file', 'gallery'].includes(type) ? await checkAccess(pg, objectid, id) : {};
47
-
48
- if (exists && !isAdmin(req) && uid && user?.uid !== uid) {
49
- return reply.status(403).send('access restricted: file exists, not an author');
50
- }
51
-
52
- const sqls = {
53
- comment: `delete from crm.communications where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'uid=$2'} and communication_id=$3`,
54
- checklist: `delete from crm.checklists where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'uid=$2'} and checklist_id=$3`,
55
- file: `update crm.files set file_status=3 where entity_id=$1 and ${!exists || isAdmin(req) ? '$2=$2' : 'uid=$2'} and file_id=$3 returning uploaded_name`,
56
- gallery: `update crm.files set file_status=3 where entity_id=$1 and ${!exists || isAdmin(req) ? '$2=$2' : 'uid=$2'} and file_id=$3 returning uploaded_name`,
57
- };
58
-
59
- const sql = sqls[type];
60
- const table = {
61
- comment: 'crm.communications',
62
- checklist: 'crm.checklists',
63
- file: 'crm.files',
64
- gallery: 'crm.files',
65
- }[type];
66
-
67
- if (!sql) {
68
- return reply.status(400).send('invalid widget type');
69
- }
70
-
71
- const { rows = [] } = await pg.query(sql, [objectid, user.uid, id]);
72
-
73
- await logChanges({
74
- pg, table, id, data: rows[0], uid: user?.uid, type: 'DELETE',
75
- });
76
-
77
- return { data: { id }, user: { uid: user.uid, name: user.user_name } };
78
-
79
- }
@@ -1,136 +0,0 @@
1
- import { getMeta, getToken, pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
4
- const username = `coalesce(u.sur_name,'')||coalesce(' '||u.user_name,'') ||coalesce(' '||u.father_name,'')`;
5
-
6
- /**
7
- * Дістає CRM для widget
8
- *
9
- */
10
-
11
- export default async function widgetGet({
12
- pg = pgClients.client, user = {}, params = {}, query = {}, unittest,
13
- }, reply) {
14
- const param = user?.uid ? await getToken({
15
- token: params.objectid, mode: 'w', uid: user.uid,
16
- }) : null;
17
-
18
- const objectid = param ? JSON.parse(param)?.id : params.objectid;
19
-
20
- if (!objectid) {
21
- return reply.status(400).send('not enough params: id');
22
- }
23
-
24
- const sqls = {
25
- comment: pg.pk['admin.users']
26
- ? `select communication_id, entity_id, body, subject, c.cdate, c.uid,
27
- ${username} as username, u.login, u.avatar
28
- from crm.communications c
29
- left join admin.users u on u.uid=c.uid
30
- where entity_id=$1 order by cdate desc`
31
- : 'select communication_id, entity_id, body, subject, cdate, uid from crm.communications where entity_id=$1 order by cdate desc',
32
-
33
- history: `select * from (
34
- SELECT change_id, entity_id, entity_type, change_type, change_date, a.change_user_id, a.uid, a.cdate, b.json_agg as changes,
35
- ${username} as username, u.login, u.avatar
36
- FROM log.table_changes a
37
- left join admin.users u on a.change_user_id = u.uid
38
- left join lateral(
39
- select json_agg(row_to_json(q)) from (
40
- select change_data_id, entity_key, value_new, value_old from log.table_changes_data
41
- where change_id=a.change_id
42
- )q
43
- )b on 1=1
44
- where b.json_agg is not null and (entity_id=$1 or entity_id in (
45
- select communication_id as comments from crm.communications where entity_id=$1
46
- union all select checklist_id from crm.checklists where entity_id=$1)
47
- )
48
-
49
- union all
50
- select change_id, entity_id, entity_type, change_type, change_date, a.change_user_id, a.uid, a.cdate, b.json_agg as changes,
51
- ${username} as username, u.login, u.avatar
52
- FROM log.table_changes a
53
- left join admin.users u on a.change_user_id = u.uid
54
- left join lateral(
55
- select json_agg(o) from (
56
- select json_object_agg(entity_key, coalesce(value_new, value_old)) as o from log.table_changes_data
57
- where change_id=a.change_id and entity_key not in ('uid', 'file_status', 'editor_id', 'cdate', 'editor_date', 'entity_id')
58
- )q
59
- )b on 1=1
60
- where a.change_type in ('INSERT', 'DELETE') and a.entity_id in (select file_id from crm.files where entity_id=$1)
61
- limit 100
62
-
63
- )q order by cdate desc limit 100`,
64
-
65
- checklist: pg.pk['admin.users']
66
- ? `SELECT checklist_id, entity_id, subject, is_done, done_date, c.uid, c.cdate, ${username} as username, u.login, u.avatar
67
- FROM crm.checklists c
68
- left join admin.users u on u.uid=c.uid
69
- where entity_id=$1 order by cdate desc`
70
- : 'SELECT checklist_id, entity_id, subject, is_done, done_date, uid, cdate FROM crm.checklists where entity_id=$1 order by cdate desc',
71
-
72
- file: pg.pk['admin.users']
73
- ? `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
74
- ${username} as username, u.login, isverified, u.avatar, u.uid as author, file_status
75
- FROM crm.files c
76
- left join admin.users u on u.uid=c.uid
77
- where entity_id=$1 and file_status<>3 order by cdate desc`
78
- : `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, uid, cdate, file_type, ismain,
79
- isverified, uid as author, file_status FROM crm.files c where entity_id=$1 and file_status<>3 order by cdate desc`,
80
- gallery: pg.pk['admin.users']
81
- ? `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
82
- ${username} as username, u.login, u.avatar, isverified, u.avatar, c.uid as author, file_status
83
- FROM crm.files c
84
- left join admin.users u on u.uid=c.uid
85
- where entity_id=$1 and file_status<>3 and ext = any($2) order by cdate desc`
86
- : `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, ismain,
87
- isverified, uid as author, file_status FROM crm.files c where entity_id=$1 and file_status<>3 and ext = any($2) order by cdate desc`,
88
-
89
- };
90
-
91
- const q = sqls[params.type];
92
-
93
- if (!q) {
94
- return reply.status(400).send('invalid widget type');
95
- }
96
-
97
-
98
- /* data */
99
- const time = [Date.now()];
100
- const { rows = [] } = await pg.query(q, [objectid, params.type === 'gallery' ? galleryExtList : null].filter((el) => el));
101
- rows.forEach(row => Object.assign(row, { username: row.username?.trim?.() || row.login }));
102
- time.push(Date.now());
103
-
104
- /* Object info */
105
- const { tableName } = pg.pk['log.table_changes'] ? await pg.query(
106
- 'select entity_type as "tableName" from log.table_changes where entity_id=$1 limit 1',
107
- [objectid]
108
- ).then(el => el.rows?.[0] || {}) : {};
109
-
110
- const { pk, columns = [] } = await getMeta({ pg, table: tableName });
111
-
112
- const authorIdColumn = columns.find(col => ['uid', 'created_by'].includes(col.name))?.name;
113
-
114
- if (!pk && params.type === 'history' && !unittest) {
115
- return reply.status(404).send('log table not found');
116
- }
117
-
118
- const q1 = `select ${username} as author, u.login, a.cdate, a.editor_date from ${tableName} a
119
- left join admin.users u on a.${authorIdColumn}=u.uid where a.${pk}=$1 limit 1`;
120
-
121
- const data = pg.pk['admin.users'] && pk && tableName ? await pg.query(q, [objectid, params.type === 'gallery' ? galleryExtList : null].filter((el) => el)).then(el => el.rows?.[0] || {}) : {};
122
-
123
- if (query.debug && user?.user_type === 'admin') {
124
- return {
125
- q, type: params.type, q1, id: objectid, data,
126
- };
127
- }
128
-
129
- return {
130
- time: { data: time[1] - time[0] },
131
- rows,
132
- user: { uid: user?.uid, name: user?.user_name },
133
- data: { author: data?.author, cdate: data?.cdate, edate: data?.editor_date },
134
- objectid: params.objectid,
135
- };
136
- }
@@ -1,99 +0,0 @@
1
- import path from 'path';
2
-
3
- import {
4
- getMeta, dataInsert, dataUpdate, applyHook, uploadMultiPart,
5
- } from '@opengis/fastify-table/utils.js';
6
-
7
- const tableList = {
8
- comment: 'crm.communications',
9
- gallery: 'crm.files',
10
- checklist: 'crm.checklists',
11
- };
12
- const pkList = {
13
- comment: 'communication_id',
14
- checklist: 'checklist_id',
15
- gallery: 'file_id',
16
- };
17
-
18
- const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
19
-
20
- export default async function widgetSet(req, reply) {
21
- const {
22
- pg, params = {}, session = {}, headers = {}, body = {}, user = {}, unittest,
23
- } = req;
24
- const { type, id, objectid } = params;
25
-
26
- if (!['comment', 'checklist', 'file', 'gallery'].includes(type)) {
27
- return reply.status(400).send('param type not valid');
28
- }
29
-
30
- if (!objectid) {
31
- return reply.status(400).send('not enough params: id');
32
- }
33
-
34
- const table = tableList[type];
35
-
36
- // dsadasdad
37
- if (['gallery', 'file'].includes(type) && headers['content-type']?.split?.(';')?.shift?.() === "multipart/form-data") {
38
- const file = await uploadMultiPart(req);
39
- const extName = path.extname(file.filepath).slice(1).toLowerCase();
40
-
41
- const data = {
42
- uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
43
- file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
44
- ext: extName,
45
- size: file?.size,
46
- file_status: 1,
47
- uid: user?.uid || 1,
48
- entity_id: objectid,
49
- };
50
-
51
- if (type === 'gallery' && !galleryExtList.includes(extName.toLowerCase())) {
52
- return reply.status(400).send('invalid file extension');
53
- }
54
-
55
- const { rows = [] } = await dataInsert({
56
- pg, table: 'crm.files', data, uid: user?.uid,
57
- });
58
-
59
- if (type === 'gallery') {
60
- await pg.query(`update crm.files set ismain=true
61
- where entity_id=$1
62
- and file_id=$2
63
- and (select count(*) = 0 from crm.files where entity_id=$1 and ismain)`, [objectid, rows[0]?.file_id]);
64
- }
65
-
66
- return {
67
- rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
68
- };
69
- }
70
- const { pk } = await getMeta({ pg, table });
71
-
72
- if (!pk) {
73
- return reply.status(404).send('table not found');
74
- }
75
-
76
- const data = { ...body, uid: user?.uid, entity_id: objectid };
77
-
78
- await applyHook('onWidgetSet', {
79
- pg,
80
- link: req.path,
81
- id,
82
- objectid,
83
- session,
84
- type,
85
- payload: data,
86
- });
87
-
88
- const result = id
89
- ? await dataUpdate({
90
- pg, table, data, id, uid: user?.uid,
91
- })
92
- : await dataInsert({
93
- pg, table, data, uid: user?.uid,
94
- });
95
-
96
- return {
97
- rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
98
- };
99
- }
@@ -1,12 +0,0 @@
1
- import { pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function onWidgetSet({
4
- pg = pgClients.client, id, objectid, type, payload = {},
5
- }) {
6
- if (!id || !objectid || type !== 'gallery') {
7
- return null;
8
- }
9
- if (payload?.ismain) {
10
- await pg.query('update crm.files set ismain=false where entity_id=$1 and file_id<>$2', [objectid, id]);
11
- }
12
- }
@@ -1,20 +0,0 @@
1
- import { addHook } from '@opengis/fastify-table/utils.js';
2
-
3
- import widgetDel from './controllers/widget.del.js';
4
- import widgetSet from './controllers/widget.set.js';
5
- import widgetGet from './controllers/widget.get.js';
6
- import fileEdit from './controllers/file.edit.js';
7
-
8
- import onWidgetSet from './hook/onWidgetSet.js';
9
-
10
- import { tableSchema } from './schema.js';
11
-
12
- const policy = ['site'];
13
-
14
- export default async function route(fastify) {
15
- fastify.delete(`/widget/:type/:objectid/:id`, { config: { policy }, scheme: tableSchema }, widgetDel);
16
- fastify.post(`/widget/:type/:objectid/:id?`, { config: { policy }, scheme: tableSchema }, widgetSet);
17
- fastify.put(`/file-edit/:id`, { config: { policy }, scheme: tableSchema }, fileEdit);
18
- fastify.get(`/widget/:type/:objectid`, { config: { policy: ['public'] }, scheme: tableSchema }, widgetGet);
19
- addHook('onWidgetSet', onWidgetSet);
20
- }
@@ -1,13 +0,0 @@
1
- const tableSchema = {
2
- params: {
3
- // type: { type: 'string', pattern: '^([\\d\\w]+)$' },
4
- objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
5
- id: { type: 'string', pattern: '^([\\d\\w]+)$' },
6
- },
7
- querystring: {
8
- debug: { type: 'string', pattern: '^(\\d+)$' },
9
- },
10
- };
11
-
12
- export default null;
13
- export { tableSchema }