@opengis/admin 0.3.9 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -48,7 +48,7 @@
48
48
  "@fullcalendar/vue3": "^6.1.15",
49
49
  "@opengis/fastify-auth": "^1.0.73",
50
50
  "@opengis/fastify-file": "^1.0.42",
51
- "@opengis/fastify-table": "^1.2.44",
51
+ "@opengis/fastify-table": "^1.2.45",
52
52
  "@opengis/v3-core": "^0.3.58",
53
53
  "@opengis/v3-filter": "^0.0.72",
54
54
  "@tabler/icons-vue": "^3.28.1",
package/plugin.js CHANGED
@@ -26,5 +26,6 @@ async function plugin(fastify, opts = config) {
26
26
  fastify.register(import('./server/routes/access/index.mjs'), opts);
27
27
  fastify.register(import('./server/routes/report/index.mjs'), opts);
28
28
  fastify.register(import('./server/routes/print/index.mjs'), opts);
29
+ fastify.register(import('./server/routes/util/index.mjs'), opts);
29
30
  }
30
31
  export default fp(plugin)
@@ -13,6 +13,7 @@ import mdToHTML from "./utils/mdToHTML.js";
13
13
 
14
14
  import ifCond from "./temp/ifCond.js";
15
15
  import contentList from "./temp/contentList.js";
16
+ import paddingNumber from './utils/paddingNumber.js';
16
17
 
17
18
 
18
19
 
@@ -33,4 +34,7 @@ export default async function route() {
33
34
  handlebarsSync.registerHelper('empty', () => { });
34
35
  handlebars.registerHelper('coalesce', coalesce);
35
36
  handlebarsSync.registerHelper('coalesce', coalesce);
37
+
38
+ handlebarsSync.registerHelper('paddingNumber', paddingNumber);
39
+ handlebars.registerHelper('paddingNumber', paddingNumber);
36
40
  }
@@ -0,0 +1,4 @@
1
+ export default function (num) {
2
+ const padding = arguments.length === 3 ? arguments[1] : 6;
3
+ return num.toLocaleString('en', { minimumIntegerDigits: padding, useGrouping: false })
4
+ }
@@ -15,7 +15,7 @@ function formatSchema(schema, user, opt) {
15
15
  obj.colModel.forEach(parseDataTables);
16
16
  }
17
17
  }
18
- Object.keys(schema).map(key => ({ key, ...schema[key] })).forEach(parseDataTables);
18
+ Object.keys(schema || {}).map(key => ({ key, ...schema[key] })).forEach(parseDataTables);
19
19
  }
20
20
 
21
21
  export default async function getTemplateApi(req) {
@@ -36,8 +36,8 @@ export default async function getTemplateApi(req) {
36
36
  }
37
37
 
38
38
  if (type === 'form' && user?.uid) {
39
- const schema = data.schema || data;
40
- formatSchema(schema, user, data.obj);
39
+ const schema = data?.schema || data;
40
+ formatSchema(schema, user, data?.obj);
41
41
  }
42
42
 
43
43
  await applyHook('afterTemplate', { name, type, data, user });
@@ -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
+ }
@@ -0,0 +1,89 @@
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
+ }
@@ -0,0 +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
+ }