@opengis/gis 0.2.171 → 0.2.172
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,19 +1,27 @@
|
|
|
1
1
|
import { pgClients, getFilterSQL, getTemplate } from "@opengis/fastify-table/utils.js";
|
|
2
|
-
import { attachClassifiers } from './funcs/classifiers.js';
|
|
3
|
-
const pg = pgClients.client;
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
const { params = {}, query = {} } = req;
|
|
7
|
-
const { slug, id } = params;
|
|
8
|
-
const { filter, page = 1 } = query;
|
|
3
|
+
import { BadRequestError, NotFoundError } from "@opengis/fastify-table/errors.js";
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
import { attachClassifiers } from './classifiers.js';
|
|
6
|
+
|
|
7
|
+
export default async function mapRegistry({
|
|
8
|
+
slug, id, filter, limit: queryLimit, page = 1
|
|
9
|
+
}, pg = pgClients.client) {
|
|
10
|
+
if (!slug || !id) {
|
|
11
|
+
throw BadRequestError('Params slug and id is required');
|
|
12
|
+
}
|
|
11
13
|
|
|
12
14
|
const mapTemplate = await getTemplate('map', slug);
|
|
13
|
-
|
|
15
|
+
|
|
16
|
+
if (!mapTemplate) {
|
|
17
|
+
throw NotFoundError('Template not found');
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
const listWidget = mapTemplate.widgets?.find(w => w.type === 'list' && w.visible !== false && w.id === id);
|
|
16
|
-
|
|
21
|
+
|
|
22
|
+
if (!listWidget) {
|
|
23
|
+
throw NotFoundError('List widget not found');
|
|
24
|
+
}
|
|
17
25
|
|
|
18
26
|
const {
|
|
19
27
|
table,
|
|
@@ -25,7 +33,7 @@ const { params = {}, query = {} } = req;
|
|
|
25
33
|
} = listWidget;
|
|
26
34
|
|
|
27
35
|
const { columns = [], filters = [], limit: configLimit = 20 } = config;
|
|
28
|
-
const limit =
|
|
36
|
+
const limit = queryLimit || configLimit;
|
|
29
37
|
const offset = limit * (page - 1);
|
|
30
38
|
const selectColumns = columns.map(col => col.name);
|
|
31
39
|
|
|
@@ -35,7 +43,7 @@ const { params = {}, query = {} } = req;
|
|
|
35
43
|
|
|
36
44
|
|
|
37
45
|
const { q: sqlFilter } = filter
|
|
38
|
-
? await getFilterSQL({ table, filter
|
|
46
|
+
? await getFilterSQL({ table, filter })
|
|
39
47
|
: { q: '1=1' };
|
|
40
48
|
|
|
41
49
|
const whereConditions = [baseQuery, sqlFilter].filter(Boolean).join(" AND ");
|
|
@@ -43,7 +51,7 @@ const { params = {}, query = {} } = req;
|
|
|
43
51
|
|
|
44
52
|
const sqlBase = `FROM ${table} ${whereClause}`;
|
|
45
53
|
const sqlOrder = order ? `ORDER BY ${order}` : "";
|
|
46
|
-
const sqlLimit = `LIMIT $1 OFFSET $2`;
|
|
54
|
+
const sqlLimit = `LIMIT $1::bigint OFFSET $2::bigint`;
|
|
47
55
|
const sqlSelect = `SELECT ${pk} as id, ${selectColumns.join(", ")}
|
|
48
56
|
${sqlBase}`;
|
|
49
57
|
const dataQuery = `${sqlSelect} ${sqlOrder} ${sqlLimit}`;
|