@opengis/admin 0.4.21 → 0.4.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.
Files changed (84) hide show
  1. package/README.md +97 -97
  2. package/dist/{add-page-DX8I-Ibw.js → add-page-8ASRlQMS.js} +1 -1
  3. package/dist/{admin-interface-Cq3LktJQ.js → admin-interface-BEb1DlT2.js} +6 -6
  4. package/dist/{admin-view-CyZiD4rI.js → admin-view-BcWfEfRW.js} +7 -7
  5. package/dist/admin.js +1 -1
  6. package/dist/admin.umd.cjs +28 -28
  7. package/dist/assets/logo.svg +41 -41
  8. package/dist/{card-view-SjNlmAdw.js → card-view-BbzJnvoN.js} +1 -1
  9. package/dist/{edit-page-CNbf1qdc.js → edit-page-NFAOI00G.js} +1 -1
  10. package/dist/{import-file-Dl5JtLqU.js → import-file-DJR1XXLF.js} +4834 -4812
  11. package/dist/{profile-page-4x0ereNR.js → profile-page-CBSCi6Db.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 +3 -3
  38. package/plugin.js +3 -3
  39. package/server/helpers/core/coalesce.js +7 -7
  40. package/server/helpers/core/select.js +48 -48
  41. package/server/helpers/core/token.js +18 -18
  42. package/server/helpers/list/buttonHelper.js +21 -21
  43. package/server/helpers/list/utils/button.js +5 -5
  44. package/server/helpers/temp/contentList.js +58 -58
  45. package/server/helpers/temp/ifCond.js +101 -101
  46. package/server/helpers/utils/button.js +5 -5
  47. package/server/helpers/utils/mdToHTML.js +17 -17
  48. package/server/plugins/cron.js +10 -10
  49. package/server/plugins/docs.js +28 -28
  50. package/server/routes/calendar/controllers/calendar.data.js +124 -125
  51. package/server/routes/calendar/index.mjs +7 -7
  52. package/server/routes/notifications/controllers/readNotifications.js +18 -18
  53. package/server/routes/notifications/controllers/testEmail.js +35 -35
  54. package/server/routes/notifications/controllers/userNotifications.js +53 -53
  55. package/server/routes/notifications/hook/onWidgetSet.js +56 -56
  56. package/server/routes/notifications/index.mjs +26 -26
  57. package/server/routes/root.mjs +3 -3
  58. package/server/routes/user/controllers/user.cls.id.js +14 -14
  59. package/server/routes/user/controllers/user.cls.js +72 -72
  60. package/server/routes/user/controllers/user.info.js +17 -17
  61. package/server/templates/cls/itree.recrzone_category.json +73 -73
  62. package/server/templates/cls/test.json +9 -9
  63. package/server/templates/form/admin.user_cls.data.form.json +49 -49
  64. package/server/templates/form/admin.user_group_rel.form.json +21 -21
  65. package/server/templates/form/form-user-pass.json +10 -10
  66. package/server/templates/form/form-user_group.json +39 -39
  67. package/server/templates/form/form-users.json +156 -156
  68. package/server/templates/form/user_group_access.form.json +22 -22
  69. package/server/templates/select/account_id.json +2 -2
  70. package/server/templates/table/gis.dataset.table.json +43 -43
  71. package/server/templates/table/management.user_group.table.json +112 -112
  72. package/server/templates/table/management.users.table.json +126 -126
  73. package/server/utils/addNotification.js +21 -21
  74. package/server/utils/sendNotification.js +89 -89
  75. package/utils.js +13 -2
  76. package/server/plugins/access/funcs/getAdminAccess.js +0 -13
  77. package/server/plugins/access/index.mjs +0 -6
  78. package/server/routes/access/controllers/access.group.js +0 -30
  79. package/server/routes/access/controllers/access.group.post.js +0 -55
  80. package/server/routes/access/controllers/access.interface.js +0 -34
  81. package/server/routes/access/index.mjs +0 -11
  82. package/server/routes/access/schema.mjs +0 -68
  83. package/server/routes/util/controllers/code.generator.js +0 -89
  84. package/server/routes/util/index.mjs +0 -5
@@ -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
+ }
package/utils.js CHANGED
@@ -1,13 +1,24 @@
1
1
  import yamlSafe from 'js-yaml';
2
2
 
3
- import { handlebars, handlebarsSync, addTemplateDir } from '@opengis/fastify-table/utils.js';
3
+ import { config, handlebars, handlebarsSync, addTemplateDir } from '@opengis/fastify-table/utils.js';
4
4
 
5
5
 
6
6
  import isAdmin from './server/utils/isAdmin.js';
7
7
  import addNotification from './server/utils/addNotification.js';
8
8
  import sendNotification from './server/utils/sendNotification.js';
9
9
 
10
- import getAdminAccess from './server/plugins/access/funcs/getAdminAccess.js';
10
+ async function getAdminAccess({
11
+ id, user = {},
12
+ }) {
13
+ if (!id) {
14
+ return { message: 'not enough params: id', status: 400 };
15
+ }
16
+
17
+ if (!config?.local && !['admin'].includes(user.user_type, user.type)) {
18
+ return { message: 'access restricted: admin', status: 403 };
19
+ }
20
+ return null;
21
+ }
11
22
 
12
23
  function loadSafe(yml) {
13
24
  try {
@@ -1,13 +0,0 @@
1
- import { config } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function getAdminAccess({
4
- id, user = {},
5
- }) {
6
- if (!id) {
7
- return { message: 'not enough params: id', status: 400 };
8
- }
9
-
10
- if (!config?.local && !['admin'].includes(user.user_type, user.type)) {
11
- return { message: 'access restricted: admin', status: 403 };
12
- }
13
- }
@@ -1,6 +0,0 @@
1
- import getAdminAccess from './funcs/getAdminAccess.js';
2
-
3
- async function plugin(fastify) {
4
- // fastify.decorate('getAdminAccess', getAdminAccess);
5
- }
6
- export default plugin;
@@ -1,30 +0,0 @@
1
- import { pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- import { getAdminAccess } from '../../../../utils.js';
4
-
5
- export default async function accessGroup({
6
- pg = pgClients.client, params = {}, session = {},
7
- }) {
8
- const { user = {} } = session?.passport || {};
9
-
10
- if (!params?.id) {
11
- return { message: 'not enough params: id', status: 400 };
12
- }
13
-
14
- // restrict access - admin only
15
- const check = await getAdminAccess({
16
- id: params.id, user,
17
- });
18
- if (check) return check;
19
-
20
- const { rows: routes = [] } = await pg.query(`select a.route_id as path, b.actions from admin.routes a
21
- left join admin.role_access b on a.route_id=b.route_id
22
- where b.role_id=$1`, [params.id]);
23
-
24
- const { rows: users = [] } = await pg.query(`select user_uid as id, user_name as name, access_granted,
25
- b.cdate as user_created, b.last_activity_date as last_activity from admin.user_roles a
26
- left join admin.users b on a.user_uid=b.uid
27
- where a.role_id=$1`, [params.id]);
28
-
29
- return { routes, users };
30
- }
@@ -1,55 +0,0 @@
1
- import { pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- import { getAdminAccess } from '../../../../utils.js';
4
- import accessGroup from './access.group.js';
5
-
6
- export default async function accessGroupPost({
7
- pg = pgClients.client, params = {}, session = {}, body = {},
8
- }) {
9
- const { id } = params;
10
- const { user } = session?.passport || {};
11
- if (!user) return { status: 403, message: 'access restricted' }
12
-
13
- // restrict access - admin only
14
- const check = await getAdminAccess({ id, user });
15
- if (check) return check;
16
-
17
- const { users = [], routes = [] } = body;
18
-
19
- if (!routes?.length) {
20
- // return { message: 'not enough params: users / routes', status: 400 };
21
- await pg.query(`delete from admin.role_access where role_id=$1`, [id]);
22
-
23
- if (!users?.length) {
24
- return { message: { id, routes }, status: 200 };
25
- }
26
- }
27
-
28
- if (routes?.length) {
29
- const { routesDB = [] } = await pg.query('select array_agg(route_id) as "routesDB" from admin.routes where enabled')
30
- .then((res1) => res1.rows?.[0] || {});
31
- await pg.query(`delete from admin.role_access where role_id=$1;`, [id]);
32
-
33
-
34
- const q = `insert into admin.role_access(role_id,route_id,actions) values ($1,$2,$3)`;
35
- await Promise.all(routes.filter(el => routesDB.includes(el.path) && el.actions).map(el => pg.query(q, [id, el.path, el.actions])))
36
-
37
- const { rows } = await pg.query(`select a.route_id as path, b.actions as actions from admin.routes a
38
- left join admin.role_access b on a.route_id=b.route_id
39
- where b.role_id=$1`, [id]);
40
-
41
- if (!users?.length) {
42
- return { message: { id, routes: rows }, status: 200 };
43
- }
44
- }
45
-
46
- const q = `delete from admin.user_roles where role_id='${id.replace(/'/g, "''")}';
47
- insert into admin.user_roles(role_id,user_uid,access_granted)
48
- values ${users.filter((el) => el?.id).map((el) => `('${id.replace(/'/g, "''")}','${el.id.replace(/'/g, "''")}','${user?.uid?.replace(/'/g, "''")}')`)}`;
49
-
50
- await pg.query(q);
51
-
52
- const res = await accessGroup({ pg, params, session });
53
-
54
- return res;
55
- }
@@ -1,34 +0,0 @@
1
- import { pgClients, metaFormat } from '@opengis/fastify-table/utils.js';
2
- import { getAdminAccess } from '../../../../utils.js';
3
-
4
- const q = `select a.route_id as id, coalesce(b.user_uid, d.user_uid) as user_uid, coalesce(d.actions, b.actions, array['view']) as actions, b.scope, c.role_id
5
- from admin.routes a
6
- left join admin.role_access b on
7
- a.route_id=b.route_id
8
- left join admin.roles c on
9
- b.role_id=c.role_id
10
- and c.enabled
11
- left join admin.user_roles d on
12
- c.role_id=d.role_id
13
- and ( case when
14
- d.expiration is not null
15
- then d.expiration > CURRENT_DATE
16
- else 1=1
17
- end )
18
- where $1 in (a.route_id, a.alias, a.table_name) and coalesce(b.user_uid, d.user_uid) is not null`;
19
-
20
- export default async function accessInterface(req) {
21
- const { pg = pgClients.client, params = {}, user = {} } = req;
22
-
23
- // restrict access - admin only
24
- const check = await getAdminAccess({
25
- id: params.name, user,
26
- });
27
- if (check) return check;
28
-
29
- const { rows = [] } = await pg.query(q, [params.name]);
30
-
31
- const cls = { user_uid: 'core.user_uid', actions: 'core.actions', role_id: 'core.roles' };
32
- await metaFormat({ rows, cls, sufix: false });
33
- return { rows };
34
- }
@@ -1,11 +0,0 @@
1
- import accessGroup from "./controllers/access.group.js";
2
- import accessGroupPost from "./controllers/access.group.post.js";
3
- import accessInterface from "./controllers/access.interface.js";
4
-
5
- import { accessGroupPostSchema, accessGroupSchema, accessInterfaceSchema } from "./schema.mjs";
6
-
7
- export default async function route(fastify) {
8
- fastify.get('/access-group/:id', { schema: accessGroupSchema }, accessGroup);
9
- fastify.post('/access-group/:id', { schema: accessGroupPostSchema }, accessGroupPost);
10
- fastify.get('/access-interface/:name', { schema: accessInterfaceSchema }, accessInterface);
11
- }
@@ -1,68 +0,0 @@
1
- export default null;
2
- export { accessGroupSchema, accessGroupPostSchema, accessInterfaceSchema }
3
-
4
- const accessGroupSchema = {
5
- params: {
6
- type: 'object',
7
- properties: {
8
- id: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
9
- },
10
- required: ['id'],
11
- },
12
- };
13
-
14
- const accessInterfaceSchema = {
15
- params: {
16
- type: 'object',
17
- properties: {
18
- name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
19
- },
20
- required: ['name'],
21
- },
22
- };
23
-
24
- const accessGroupPostSchema = {
25
- params: {
26
- type: 'object',
27
- properties: {
28
- id: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
29
- },
30
- required: ['id'],
31
- },
32
- body: {
33
- type: 'object',
34
- properties: {
35
- users: {
36
- type: 'array',
37
- items: {
38
- type: 'object',
39
- properties: {
40
- id: {
41
- type: 'string',
42
- pattern: '^([\\d\\w._-]+)$',
43
- },
44
- },
45
- },
46
- },
47
- routes: {
48
- type: 'array',
49
- /*items: {
50
- type: 'object',
51
- properties: {
52
- path: {
53
- type: 'string',
54
- pattern: '^([\\d\\w._-]+)$',
55
- },
56
- actions: {
57
- type: 'array',
58
- items: {
59
- type: 'string',
60
- enum: ['get', 'add', 'edit', 'del'],
61
- },
62
- },
63
- },
64
- },*/
65
- },
66
- },
67
- },
68
- };
@@ -1,89 +0,0 @@
1
- import { getTemplate, handlebarsSync, pgClients, getToken } from "@opengis/fastify-table/utils.js";
2
-
3
- function dayOfTheYear(date) {
4
- const start = new Date(date.getFullYear(), 0, 0);
5
- const diff = (date - start) + ((start.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000);
6
- const oneDay = 1000 * 60 * 60 * 24;
7
- const day = Math.floor(diff / oneDay);
8
- return day;
9
- }
10
-
11
- export default async function codeGenerator({
12
- pg = pgClients.client, params = {}, user = {}, query = {},
13
- }, reply) {
14
- const { token, column } = params;
15
- const data = query.data?.split?.(';') || [];
16
-
17
- if (!token || !column) {
18
- return reply.status(400).send('not enough params: token / column');
19
- }
20
-
21
- if (!user?.uid) {
22
- return reply.status(401).send('access restricted: token');
23
- }
24
-
25
- const tokenData = await getToken({ token, uid: user?.uid, json: 1 }) || {};
26
-
27
- if (!tokenData?.form || !tokenData?.table) {
28
- return reply.status(401).send('token not allow');
29
- }
30
-
31
- const loadTemplate = await getTemplate('form', tokenData.form);
32
- const schema = loadTemplate?.schema || loadTemplate;
33
-
34
- if (!schema) {
35
- return reply.status(404).send('form not found');
36
- }
37
-
38
- if (!schema?.[column]?.template) {
39
- return reply.status(400).send('template not specified');
40
- }
41
-
42
- const columnValue = data.find(el => el.startsWith(column))?.split('=')?.pop();
43
-
44
- const loadTable = await getTemplate('table', tokenData.table);
45
- const table = loadTable?.table || tokenData.table;
46
-
47
- if (!pg.pk?.[table]) {
48
- return reply.status(404).send('table pk not found');
49
- }
50
-
51
- const { count = 0 } = await pg.query(
52
- `select count(*) from ${table} where ${columnValue ? `${column}::text = '${columnValue}'` : 'true'} limit 1`,
53
- ).then(el => el.rows?.[0] || {});
54
-
55
- const { NUMY = 0 } = await pg.query(
56
- `select ${column} as "NUMY" from ${table} where ${column} is not null and date_part('year', cdate) = $1 order by cdate desc limit 1`,
57
- [(new Date()).getFullYear()]
58
- ).then(el => el.rows?.[0] || {});
59
-
60
- const date = new Date();
61
-
62
- const template = schema[column].template.match(/NUM[M|Y] \d/g)
63
- .reduce((acc, curr) => acc.replace(
64
- curr.startsWith('{{{') ? `{{{${curr}}}}` : `{{${curr}}}`,
65
- handlebarsSync.compile(`{{paddingNumber value padding}}`)({ padding: curr.substring(4, curr.length)?.trim?.(), value: curr.startsWith('NUMY') ? NUMY : +count + 1 })),
66
- schema[column].template
67
- );
68
- const result = handlebarsSync.compile(template)({
69
- HH: date.getHours(), // hours 24h: 14:00 = 14
70
- HH12: (date.getHours() + 24) % 12 || 12, // hours 12h: 14:00 = 2
71
- HH24: date.getHours(), // hours 24h: 14:00 = 14
72
- MI: date.getMinutes(), // minutes
73
- SS: date.getSeconds(), // seconds
74
-
75
- YYYY: date.getFullYear(), // full year: 2025
76
- YY: date.getFullYear().toString().substring(2, 4), // last 2 digits of year: 25
77
-
78
- MONTH: date.toLocaleString('en', { month: 'long' }).toUpperCase(), // month name: MARCH
79
- MON: date.toLocaleString('en', { month: 'long' }).substring(0, 3).toUpperCase(), // month name abbrev: MAR
80
- MM: date.getMonth() + 1, // month number: 1 - january, 12 - december
81
-
82
- D: date.getDay(), // day of the week: 1 - monday, 7 - sunday
83
- DD: date.getDate(), // day of the month: january 4 = 4
84
- DDD: dayOfTheYear(date), // day of the year: march 4 = 63
85
- ...data,
86
- });
87
-
88
- return reply.status(200).send(result);
89
- }
@@ -1,5 +0,0 @@
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
- }