@opengis/fastify-table 1.3.48 → 1.3.50
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/index.js
CHANGED
|
@@ -59,7 +59,7 @@ async function plugin(fastify, opt) {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
// core migrations (second argument for core only)
|
|
62
|
-
|
|
62
|
+
execMigrations(path.join(cwd, 'server/migrations'), true).catch(err => console.log(err));
|
|
63
63
|
|
|
64
64
|
// core templates && cls
|
|
65
65
|
config.templates?.forEach(el => addTemplateDir(el));
|
package/package.json
CHANGED
|
@@ -1,50 +1,49 @@
|
|
|
1
|
-
import getPG from
|
|
2
|
-
import getSelect from '../../plugins/table/funcs/getSelect.js';
|
|
3
|
-
|
|
1
|
+
import { getPG, getSelect } from "../../../utils.js";
|
|
4
2
|
const pg = getPG();
|
|
5
3
|
|
|
4
|
+
// todo: remove dupe from npm/admin?
|
|
6
5
|
export default async function select(ids, options) {
|
|
7
|
-
if (!ids && ids
|
|
8
|
-
return ids;
|
|
9
|
-
}
|
|
10
|
-
if (Array.isArray(ids) && ids.length === 0) {
|
|
6
|
+
if (!ids || (Array.isArray(ids) && ids.length === 0) || ids === '') {
|
|
11
7
|
return '';
|
|
12
8
|
}
|
|
13
9
|
|
|
14
10
|
const data = options.hash?.data;
|
|
15
|
-
if (!data) return '';
|
|
16
|
-
|
|
11
|
+
if (!data && data !== false && data !== 0) return '';
|
|
17
12
|
try {
|
|
18
13
|
const idsArray = Array.isArray(ids) ? ids : [ids];
|
|
19
14
|
|
|
20
15
|
const classifier = await getSelect(data);
|
|
21
16
|
|
|
17
|
+
|
|
18
|
+
|
|
22
19
|
if (!classifier) return `Не знайдено класифікатор ${data}`;
|
|
23
20
|
|
|
21
|
+
const arr = classifier.arr || []
|
|
24
22
|
if (classifier.sql && typeof classifier.sql === 'string') {
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
25
26
|
const metaQuery = `SELECT * FROM (${classifier.sql})q LIMIT 0`;
|
|
26
27
|
const meta = await pg.query(metaQuery);
|
|
27
28
|
const idColumn = meta.fields[0].name;
|
|
28
29
|
const textColumn = meta.fields[1].name;
|
|
29
30
|
|
|
30
|
-
const
|
|
31
|
+
const q = `SELECT "${idColumn}" AS id, "${textColumn}" AS text FROM (${classifier.sql}) q WHERE "${idColumn}"::text = ANY($1::text[])`;
|
|
31
32
|
const values = [idsArray.map(id => String(id))];
|
|
32
33
|
|
|
33
|
-
const { rows } = await pg.query(
|
|
34
|
-
|
|
35
|
-
}
|
|
34
|
+
const { rows } = await pg.query(q, values);
|
|
35
|
+
Object.assign(arr, rows);
|
|
36
36
|
|
|
37
|
-
if (!Array.isArray(classifier?.arr) || !classifier.arr.length || !classifier.arr.every(item => typeof item === 'object' && item !== null)) {
|
|
38
|
-
return ids;
|
|
39
37
|
}
|
|
38
|
+
if (!arr.length) return idsArray;
|
|
40
39
|
|
|
41
40
|
const results = idsArray.map(id => {
|
|
42
|
-
const result =
|
|
41
|
+
const result = arr.find(el => String(el.id) == String(id));
|
|
43
42
|
return result ? result.text : '';
|
|
44
43
|
});
|
|
45
44
|
|
|
46
45
|
return results.filter(Boolean).join(', ');
|
|
47
|
-
} catch (
|
|
48
|
-
return `Сталася помилка.<!-- err: ${
|
|
46
|
+
} catch (err) {
|
|
47
|
+
return `Сталася помилка.<!-- err: ${err.toString()} -->`;
|
|
49
48
|
}
|
|
50
49
|
}
|
|
@@ -14,7 +14,7 @@ export default async function filterAPI(req) {
|
|
|
14
14
|
const { fields: columns = [] } = await pg.query(`select * from ${loadTable.table} t ${sqlTable} limit 0`);
|
|
15
15
|
const { fields = [] } = await pg.query(`select * from ${loadTable.table} t limit 0`);
|
|
16
16
|
|
|
17
|
-
const optimizedSQL = `select * from ${loadTable.table} t ${sqlTable}`.replace(/{{uid}}/g, user?.uid);
|
|
17
|
+
const optimizedSQL = `select * from ${loadTable.table} t ${sqlTable} where ${loadTable.query || '1=1'}`.replace(/{{uid}}/g, user?.uid);
|
|
18
18
|
|
|
19
19
|
const filters = (loadTable?.filter_list || loadTable?.filters || loadTable?.filterList || []).concat(loadTable?.filterSql || []);
|
|
20
20
|
|