@opengis/gis 0.1.78 → 0.1.79
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
|
@@ -12,12 +12,18 @@ import getServices from './services/get.services.js';
|
|
|
12
12
|
import deleteService from './services/del.service.js';
|
|
13
13
|
import addService from './services/add.service.js';
|
|
14
14
|
|
|
15
|
+
import addGisRegistry from './registers/add.registry.js';
|
|
16
|
+
import deleteGisRegistry from './registers/del.registry.js';
|
|
17
|
+
|
|
15
18
|
async function route(app) {
|
|
16
19
|
app.put('/insert-columns/:token', insertColumns);
|
|
17
20
|
app.put('/insert-filters/:token', insertFilters);
|
|
18
21
|
app.get('/gis-registry/:slug', { config: { policy: ['public'] } }, gisRegistry);
|
|
19
22
|
app.get('/gis-registry/:slug/:objectId', { config: { policy: ['public'] } }, gisRegistry);
|
|
20
23
|
app.get('/gis-registry', { config: { policy: ['public'] } }, gisRegistryList);
|
|
24
|
+
app.post('/gis-registry', { config: { policy: ['public'] } }, addGisRegistry);
|
|
25
|
+
app.put('/gis-registry/:slug', { config: { policy: ['public'] } }, addGisRegistry);
|
|
26
|
+
app.delete('/gis-registry/:slug', { config: { policy: ['public'] } }, deleteGisRegistry);
|
|
21
27
|
app.get('/map-registry/:slug/:id', { config: { policy: ['public'] } }, mapRegistry);
|
|
22
28
|
|
|
23
29
|
app.get('/xml/:id', { config: { policy: ['public'] } }, metadataXML);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { dataInsert, dataUpdate, pgClients } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function addGisRegistry({
|
|
4
|
+
method, params = {}, body, pg = pgClients.client, user = {},
|
|
5
|
+
}, reply) {
|
|
6
|
+
if (method === 'POST') {
|
|
7
|
+
|
|
8
|
+
if (!body?.register_key) {
|
|
9
|
+
return reply.status(400).send('not enough body params: register_key');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { rows = [] } = await dataInsert({
|
|
13
|
+
pg,
|
|
14
|
+
table: 'gis.registers',
|
|
15
|
+
data: body,
|
|
16
|
+
uid: user?.uid,
|
|
17
|
+
});
|
|
18
|
+
return reply.status(200).send(rows[0]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!params.slug) {
|
|
22
|
+
return reply.status(400).send('not enough params: slug');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const id = await pg.query('select register_id from gis.registers where register_key=$1', [params.slug]).then(el => el.rows?.[0]?.register_id) || params.slug;
|
|
26
|
+
|
|
27
|
+
const row = await dataUpdate({
|
|
28
|
+
pg,
|
|
29
|
+
id,
|
|
30
|
+
table: 'gis.registers',
|
|
31
|
+
data: body,
|
|
32
|
+
uid: user?.uid,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return reply.status(200).send(row);
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { dataDelete, pgClients } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function deleteGisRegistry({
|
|
4
|
+
params = {}, pg = pgClients.client, user = {},
|
|
5
|
+
}, reply) {
|
|
6
|
+
const id = await pg.query('select register_id from gis.registers where register_key=$1', [params.slug]).then(el => el.rows?.[0]?.register_id) || params.slug;
|
|
7
|
+
|
|
8
|
+
const row = await dataDelete({
|
|
9
|
+
pg,
|
|
10
|
+
id,
|
|
11
|
+
table: 'gis.registers',
|
|
12
|
+
uid: user?.uid,
|
|
13
|
+
});
|
|
14
|
+
return reply.status(200).send(row);
|
|
15
|
+
}
|
|
@@ -2,15 +2,27 @@ import { attachClassifiers, populateFilterOptions } from './classifiers.js';
|
|
|
2
2
|
import { extractVisibleColumns } from './columns.js';
|
|
3
3
|
import { getMeta, getFilterSQL } from "@opengis/fastify-table/utils.js";
|
|
4
4
|
|
|
5
|
+
const columnType = {
|
|
6
|
+
text: 'text',
|
|
7
|
+
date: 'date',
|
|
8
|
+
bool: 'yes/no',
|
|
9
|
+
numeric: 'number',
|
|
10
|
+
integer: 'number',
|
|
11
|
+
'timestamp without time zone': 'date',
|
|
12
|
+
'timestamp with time zone': 'date',
|
|
13
|
+
};
|
|
14
|
+
|
|
5
15
|
export async function handleRegistryRequest({ settings, query, object_id, offset = 0, limit = 16, page = 1, pg }) {
|
|
6
16
|
const { name, table_name, columns, filters, query: whereQuery, order, pk, register_id, is_files, view } = settings;
|
|
7
17
|
const parsedColumns = Array.isArray(columns) ? columns : JSON.parse(columns);
|
|
8
18
|
const filtersParsed = Array.isArray(filters) ? filters : JSON.parse(filters);
|
|
9
|
-
const activeFilters = filtersParsed.filter((f) => f.disabled !== true);
|
|
10
|
-
const { geom } = await getMeta({ pg, table: table_name });
|
|
19
|
+
const activeFilters = (filtersParsed || []).filter((f) => f.disabled !== true);
|
|
20
|
+
const { columns: fields1, geom } = await getMeta({ pg, table: table_name });
|
|
21
|
+
|
|
22
|
+
const fields = fields1?.map?.(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'] || 'text', label: title || name }));
|
|
11
23
|
|
|
12
24
|
const mode = object_id ? "card" : "table";
|
|
13
|
-
const visibleColumns = extractVisibleColumns(parsedColumns, mode);
|
|
25
|
+
const visibleColumns = parsedColumns ? extractVisibleColumns(parsedColumns, mode) : [];
|
|
14
26
|
const selectColumns = visibleColumns.map((col) => col.name);
|
|
15
27
|
/*const columnsInfo = visibleColumns.map((col) => ({
|
|
16
28
|
name: col.name,
|
|
@@ -26,7 +38,7 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
26
38
|
|
|
27
39
|
if (object_id) {
|
|
28
40
|
const sql = `
|
|
29
|
-
SELECT "${pk}" as id,*
|
|
41
|
+
SELECT "${pk}" as id,* ${selectColumns.length ? `, ${selectColumns.join(", ")}` : ''} ${geom ? `, st_asgeojson(${geom})::json as geom` : ''}
|
|
30
42
|
FROM ${table_name}
|
|
31
43
|
WHERE ${pk} = $1
|
|
32
44
|
`;
|
|
@@ -60,13 +72,12 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
60
72
|
: { q: '1=1' };
|
|
61
73
|
|
|
62
74
|
const whereConditions = [whereQuery, sqlFilter].filter(Boolean).join(' AND ');
|
|
63
|
-
const whereClause = whereConditions ? `WHERE ${whereConditions}` : '';
|
|
64
75
|
|
|
65
|
-
const sqlBase = `FROM ${table_name} ${
|
|
76
|
+
const sqlBase = `FROM ${table_name} WHERE ${whereConditions || 'true'}`;
|
|
66
77
|
const sqlOrder = order ? `ORDER BY ${order}` : "";
|
|
67
78
|
const sqlLimit = `LIMIT $1 OFFSET $2`;
|
|
68
79
|
|
|
69
|
-
const sqlSelect = `SELECT "${pk}" as id
|
|
80
|
+
const sqlSelect = `SELECT "${pk}" as id ${selectColumns.length ? `, ${selectColumns.join(", ")}` : ''} ${geom ? `, st_asgeojson(${geom})::json as geom` : ''} ${sqlBase}`;
|
|
70
81
|
const dataQuery = `${sqlSelect} ${sqlOrder} ${sqlLimit}`;
|
|
71
82
|
const totalQuery = `SELECT COUNT(*) ${sqlBase}`;
|
|
72
83
|
|
|
@@ -79,9 +90,12 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
79
90
|
const total = parseInt(countRes.rows[0]?.count || 0, 10);
|
|
80
91
|
|
|
81
92
|
const listConfig = {};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
|
|
94
|
+
if (parsedColumns?.length) {
|
|
95
|
+
for (const col of parsedColumns) {
|
|
96
|
+
if (col.view_type === 'title') listConfig.title = col.name;
|
|
97
|
+
if (col.view_type === 'subtitle') listConfig.subtitle = col.name;
|
|
98
|
+
}
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
await populateFilterOptions({
|
|
@@ -99,6 +113,7 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
99
113
|
total,
|
|
100
114
|
columns: visibleColumns,
|
|
101
115
|
filters: activeFilters,
|
|
116
|
+
fields,
|
|
102
117
|
limit,
|
|
103
118
|
page,
|
|
104
119
|
view,
|