@opengis/admin 0.3.10 → 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
package/server/helpers/index.js
CHANGED
@@ -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
|
}
|
@@ -31,6 +31,10 @@ export default async function codeGenerator({
|
|
31
31
|
const loadTemplate = await getTemplate('form', tokenData.form);
|
32
32
|
const schema = loadTemplate?.schema || loadTemplate;
|
33
33
|
|
34
|
+
if (!schema) {
|
35
|
+
return reply.status(404).send('form not found');
|
36
|
+
}
|
37
|
+
|
34
38
|
if (!schema?.[column]?.template) {
|
35
39
|
return reply.status(400).send('template not specified');
|
36
40
|
}
|
@@ -48,14 +52,20 @@ export default async function codeGenerator({
|
|
48
52
|
`select count(*) from ${table} where ${columnValue ? `${column}::text = '${columnValue}'` : 'true'} limit 1`,
|
49
53
|
).then(el => el.rows?.[0] || {});
|
50
54
|
|
51
|
-
const {
|
52
|
-
`select ${column} as
|
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`,
|
53
57
|
[(new Date()).getFullYear()]
|
54
58
|
).then(el => el.rows?.[0] || {});
|
55
59
|
|
56
60
|
const date = new Date();
|
57
61
|
|
58
|
-
const
|
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)({
|
59
69
|
HH: date.getHours(), // hours 24h: 14:00 = 14
|
60
70
|
HH12: (date.getHours() + 24) % 12 || 12, // hours 12h: 14:00 = 2
|
61
71
|
HH24: date.getHours(), // hours 24h: 14:00 = 14
|
@@ -72,9 +82,6 @@ export default async function codeGenerator({
|
|
72
82
|
D: date.getDay(), // day of the week: 1 - monday, 7 - sunday
|
73
83
|
DD: date.getDate(), // day of the month: january 4 = 4
|
74
84
|
DDD: dayOfTheYear(date), // day of the year: march 4 = 63
|
75
|
-
|
76
|
-
ynum,
|
77
|
-
num: +count + 1,
|
78
85
|
...data,
|
79
86
|
});
|
80
87
|
|