@opengis/admin 0.2.71 → 0.2.72
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/module/settings/form/admin.users.form.json +2 -2
- package/package.json +1 -1
- package/server/routes/calendar/controllers/calendar.data.js +78 -40
- package/server/routes/calendar/schema.js +1 -1
- package/server/routes/print/controllers/cardPrint.js +6 -1
- package/server/routes/print/index.mjs +5 -5
@@ -54,14 +54,14 @@
|
|
54
54
|
},
|
55
55
|
"login": {
|
56
56
|
"type": "Text",
|
57
|
-
"
|
57
|
+
"hidden1": true,
|
58
58
|
"ua": "Логін",
|
59
59
|
"i": "Вноситься довільний логін користувача латинськими літерами, що буде використовуватися для входу в систему",
|
60
60
|
"ru": "Логин"
|
61
61
|
},
|
62
62
|
"password": {
|
63
63
|
"type": "Password",
|
64
|
-
"
|
64
|
+
"hidden1": true,
|
65
65
|
"validators": [
|
66
66
|
{
|
67
67
|
"type": "regexp",
|
package/package.json
CHANGED
@@ -1,15 +1,21 @@
|
|
1
|
-
import {
|
1
|
+
import { getMeta, getTemplate, pgClients, handlebarsSync } from '@opengis/fastify-table/utils.js';
|
2
|
+
|
3
|
+
const isValidDate = (dateStr) => (new Date(dateStr)).toString() !== 'Invalid Date';
|
2
4
|
|
3
5
|
export default async function calendarData({
|
4
|
-
pg, params = {}, query = {}, session = {},
|
6
|
+
pg = pgClients.client, params = {}, query = {}, session = {},
|
5
7
|
}) {
|
6
8
|
const { name } = params;
|
7
|
-
const {
|
9
|
+
const { granularity = 'month' } = query;
|
10
|
+
const { user = {} } = session.passport || {};
|
11
|
+
|
8
12
|
if (!name) {
|
9
13
|
return { message: 'not enough params: name', status: 400 };
|
10
14
|
}
|
11
|
-
|
12
|
-
|
15
|
+
|
16
|
+
if (query.granularity && !['day', 'month', 'week', 'year'].includes(granularity)) {
|
17
|
+
return { message: 'invalid query params: granularity', status: 400 };
|
18
|
+
}
|
13
19
|
|
14
20
|
const body = await getTemplate('calendar', name);
|
15
21
|
|
@@ -20,10 +26,8 @@ export default async function calendarData({
|
|
20
26
|
const {
|
21
27
|
title,
|
22
28
|
table,
|
23
|
-
query: query1 = '1=1',
|
24
29
|
meta = {},
|
25
|
-
|
26
|
-
} = body;
|
30
|
+
} = body || {};
|
27
31
|
|
28
32
|
if (!table) {
|
29
33
|
return { message: 'not enough calendar params: table', status: 404 };
|
@@ -32,57 +36,91 @@ export default async function calendarData({
|
|
32
36
|
return { message: `table pkey not found: ${table}`, status: 404 };
|
33
37
|
}
|
34
38
|
|
35
|
-
const
|
36
|
-
|
39
|
+
const filterList = (body?.filter || [])
|
40
|
+
.concat(body?.filterInline || [])
|
41
|
+
.concat(body?.filterCustom || [])
|
42
|
+
.concat(body?.filterState || [])
|
43
|
+
.concat(body?.filterList || [])
|
44
|
+
.concat(body?.filters || [])
|
45
|
+
.concat(body?.filter_list || []);
|
46
|
+
|
47
|
+
const { columns = [] } = await getMeta({ pg, table });
|
48
|
+
const columnList = columns?.map((el) => el?.name);
|
49
|
+
|
50
|
+
const dateColumn = columns?.find((el) => el?.name === (meta?.date || meta?.start))?.name
|
51
|
+
|| columns?.find((el) => el?.name === 'cdate')?.name;
|
52
|
+
|
53
|
+
if (query.date && !dateColumn) {
|
54
|
+
return { message: 'invalid template params: date column not found', status: 400 };
|
55
|
+
}
|
56
|
+
|
57
|
+
if (query.date && !isValidDate(query.date)) {
|
58
|
+
return { message: 'Invalid date: out of range or incorrect format', status: 400 };
|
59
|
+
}
|
60
|
+
|
61
|
+
const filterWhere = filterList?.length && query.filter?.length
|
62
|
+
? filterList
|
63
|
+
.filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true))
|
37
64
|
.map((el) => {
|
38
65
|
const val = query.filter.split(',').find((e) => e?.split('=')?.shift()?.includes(el.column || el.name))?.split('=')?.pop();
|
39
|
-
if (val) return el.column && val ? `(${[`${el.column}::text='${val.replace(/'/g,"''")}'::text`, el.query].filter((el) => el).join(' and ')})` : el.query;
|
40
|
-
})
|
66
|
+
if (val) return el.column && val ? `(${[`${el.column}::text='${val.replace(/'/g, "''")}'::text`, el.query].filter((el) => el).join(' and ')})` : el.query;
|
67
|
+
})
|
68
|
+
.filter((el) => el)
|
69
|
+
.join(' and ')
|
41
70
|
: undefined;
|
42
|
-
// console.log(filterWhere);
|
43
71
|
|
44
|
-
|
45
|
-
|
46
|
-
|
72
|
+
const queryWhere = handlebarsSync.compile(body.query || '1=1')({ user, uid: user?.uid });
|
73
|
+
const filterDate = query.date ? `date_trunc('${granularity}', "${dateColumn}"::date)='${query.date}'::date` : undefined;
|
74
|
+
|
75
|
+
const where = [queryWhere, filterDate, filterWhere].filter((el) => el).join(' and ');
|
76
|
+
|
77
|
+
const filtersByColumn = filterList.filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true) && el?.column);
|
47
78
|
|
48
|
-
const filtersByColumn = filter.filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true) && el?.column);
|
49
|
-
|
50
79
|
const filters = [];
|
51
80
|
if (filtersByColumn?.length) {
|
52
81
|
await Promise.all(filtersByColumn.map(async (el) => {
|
53
|
-
const { rows: filterData = [] } = await pg.query(`select $
|
54
|
-
where ${el.query || '1=1'} and ${filterWhere || '1=1'} group by $
|
82
|
+
const { rows: filterData = [] } = await pg.query(`select ${el.column.replace(/'/g, "''")} as id, count(*) from ${table}
|
83
|
+
where ${el.query || '1=1'} and ${filterWhere || '1=1'} group by ${el.column.replace(/'/g, "''")}`);
|
55
84
|
if (!filterData?.length) return;
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
filterData.forEach((el1) => filters.push(el1));
|
85
|
+
|
86
|
+
const clsData = await getTemplate(['cls', 'select'], el.cls);
|
87
|
+
|
88
|
+
if (!el.cls || !clsData?.length) {
|
89
|
+
filterData.forEach((item) => filters.push(item));
|
62
90
|
return;
|
63
91
|
}
|
64
92
|
|
65
|
-
filterData.forEach((
|
66
|
-
const cls = clsData.find((item) => item.id ===
|
67
|
-
Object.assign(
|
68
|
-
filters.push(
|
93
|
+
filterData.forEach((filter) => {
|
94
|
+
const cls = clsData.find((item) => item.id === filter.id.toString());
|
95
|
+
Object.assign(filter, { title: cls?.text, color: cls?.color });
|
96
|
+
filters.push(filter);
|
69
97
|
});
|
70
98
|
}));
|
71
99
|
}
|
72
100
|
|
73
|
-
const
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
101
|
+
const filtersByPreparedQuery = filterList.filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true) && !el?.column && el?.query);
|
102
|
+
|
103
|
+
if (filtersByPreparedQuery?.length) {
|
104
|
+
await Promise.all(filtersByPreparedQuery.map(async (el) => {
|
105
|
+
const { rows = [] } = await pg.query(`select ${el.query} as id, count(*) from ${table}
|
106
|
+
where ${filterWhere || '1=1'} group by ${el.query}`);
|
107
|
+
rows.forEach((item) => filters.push(item));
|
108
|
+
}));
|
109
|
+
}
|
110
|
+
|
111
|
+
const metaColumns = Object.keys(meta)
|
112
|
+
.filter((el) => ['date', 'start', 'end', 'title', 'status'].includes(el) && columnList.includes(meta[el]))
|
113
|
+
.map((el) => `"${meta[el]}" as ${el}`);
|
114
|
+
|
115
|
+
if (!metaColumns?.length) {
|
78
116
|
return { message: `calendar param meta is invalid: invalid/empty keys`, status: 404 };
|
79
117
|
}
|
80
118
|
|
81
|
-
const q = `select
|
82
|
-
if (sql) return q;
|
119
|
+
const q = `select ${metaColumns.join(',')} from ${table} where ${where}`;
|
120
|
+
if (query?.sql && user?.user_type?.includes('admin')) return q;
|
121
|
+
|
122
|
+
const { rows = [] } = await pg.query(q);
|
83
123
|
|
84
|
-
|
85
|
-
|
86
|
-
return { title, filters, rows };
|
124
|
+
return { title, filters, granularity, sql: user?.user_type?.includes('admin') ? q : undefined, rows };
|
87
125
|
|
88
126
|
}
|
@@ -3,7 +3,7 @@ const calendarDataSchema = {
|
|
3
3
|
name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
4
4
|
},
|
5
5
|
querystring: {
|
6
|
-
date: { type: 'string', pattern: '
|
6
|
+
date: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$' },
|
7
7
|
sql: { type: 'string', pattern: '^(\\d)$' },
|
8
8
|
},
|
9
9
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import path from 'path';
|
2
2
|
import qr from 'qrcode';
|
3
|
+
import { readFile } from 'node:fs/promises';
|
4
|
+
import { fileURLToPath } from 'url';
|
3
5
|
import { createHash } from 'crypto';
|
4
6
|
|
5
7
|
import {
|
@@ -9,6 +11,8 @@ import {
|
|
9
11
|
import { grpc } from '@opengis/fastify-file/utils.js';
|
10
12
|
|
11
13
|
const { htmlToPdf } = grpc();
|
14
|
+
const filename = fileURLToPath(import.meta.url);
|
15
|
+
const dirname = path.dirname(filename);
|
12
16
|
|
13
17
|
export default async function cardPrint(req, reply) {
|
14
18
|
const { pg = pgClients.client, params = {}, query = {}, user = {} } = req;
|
@@ -62,7 +66,8 @@ export default async function cardPrint(req, reply) {
|
|
62
66
|
return { message: 'data not found', status: 404 };
|
63
67
|
}
|
64
68
|
|
65
|
-
const pt = await getTemplate('pt', template)
|
69
|
+
const pt = await getTemplate('pt', template)
|
70
|
+
|| await readFile(path.join(dirname, '../../../templates/pt/card-print.pt.hbs'), 'utf8');
|
66
71
|
|
67
72
|
const url = (req.protocol || 'https') + '://' + req.hostname + req.url;
|
68
73
|
const qrCode = `<img src="${await qr.toDataURL(url, { type: 'png', ec_level: 'M', size: 5, margin: 4 })}" alt="qrcode">`;
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import cardPrint from './controllers/cardPrint.js';
|
2
|
-
|
3
|
-
export default async function route(app) {
|
4
|
-
app.get(`/card-print/:table/:id`, cardPrint);
|
5
|
-
}
|
1
|
+
import cardPrint from './controllers/cardPrint.js';
|
2
|
+
|
3
|
+
export default async function route(app) {
|
4
|
+
app.get(`/card-print/:table/:id`, cardPrint);
|
5
|
+
}
|