@opengis/fastify-table 1.0.70 → 1.0.71
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/Changelog.md +4 -0
- package/package.json +1 -1
- package/table/controllers/form.js +19 -1
- package/table/controllers/suggest.js +1 -1
package/Changelog.md
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import getTemplate from './utils/getTemplate.js';
|
|
2
2
|
|
|
3
|
+
const sql = `select property_key as key, property_json as json, property_int as int,
|
|
4
|
+
property_text as text from admin.properties where 1=1`;
|
|
5
|
+
|
|
6
|
+
async function getSettings({ pg }) {
|
|
7
|
+
const { rows = [] } = await pg.query(sql);
|
|
8
|
+
const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.key]: curr.json || curr.int || curr.text }), {});
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
export default async function formFunction(req) {
|
|
4
13
|
const time = Date.now();
|
|
5
|
-
const { params } = req;
|
|
14
|
+
const { pg, params } = req;
|
|
6
15
|
const form = await getTemplate('form', params.form);
|
|
7
16
|
if (!form) { return { status: 404, message: 'not found' }; }
|
|
8
17
|
|
|
18
|
+
// replace settings
|
|
19
|
+
const arr = JSON.stringify(form).match(/{{settings.([^}]*)}}/g);
|
|
20
|
+
if (arr?.length) {
|
|
21
|
+
const string = JSON.stringify(form);
|
|
22
|
+
const settings = await getSettings({ pg });
|
|
23
|
+
const match = arr.reduce((acc, curr) => Object.assign(acc, { [curr]: settings[curr.replace(/^{{settings./g, '').replace(/}}$/, '')] }), {});
|
|
24
|
+
const res = Object.keys(match).reduce((s, m) => s.replace(m, match[m]), string);
|
|
25
|
+
return { time: Date.now() - time, form: JSON.parse(res) };
|
|
26
|
+
}
|
|
9
27
|
return { time: Date.now() - time, form };
|
|
10
28
|
}
|
|
@@ -15,7 +15,7 @@ export default async function suggest(req) {
|
|
|
15
15
|
if (!selectName) return { headers, status: 400, message: 'name is required' };
|
|
16
16
|
|
|
17
17
|
const meta = await getSelectMeta({ name: selectName });
|
|
18
|
-
const pg = meta
|
|
18
|
+
const pg = meta?.db ? getPG(meta.db) : pg1;
|
|
19
19
|
if (!meta) return { headers, status: 404, message: 'Not found query select ' };
|
|
20
20
|
|
|
21
21
|
const { arr, searchQuery } = meta;
|