@opengis/fastify-table 1.0.85 → 1.0.87
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 +5 -1
- package/crud/funcs/dataUpdate.js +24 -24
- package/package.json +1 -1
- package/table/index.js +1 -1
- package/test/api/table.test.js +1 -1
package/Changelog.md
CHANGED
package/crud/funcs/dataUpdate.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
|
|
5
|
-
export default async function dataUpdate({
|
|
6
|
-
table, id, data, pg: pg1,
|
|
7
|
-
}) {
|
|
8
|
-
if (!data || !table || !id) return null;
|
|
9
|
-
|
|
10
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
11
|
-
const { columns, pk } = await getMeta(table);
|
|
12
|
-
|
|
13
|
-
const names = columns?.map((el) => el.name);
|
|
14
|
-
const filterData = Object.keys(data)
|
|
15
|
-
.filter((el) => (typeof data[el] === 'boolean' ? true : data[el] && names?.includes(el)));
|
|
16
|
-
|
|
17
|
-
const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
18
|
-
|
|
19
|
-
const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`)).join(',')}
|
|
20
|
-
WHERE ${pk} = $1 returning *`;
|
|
21
|
-
//
|
|
22
|
-
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
23
|
-
return res;
|
|
24
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
|
|
5
|
+
export default async function dataUpdate({
|
|
6
|
+
table, id, data, pg: pg1,
|
|
7
|
+
}) {
|
|
8
|
+
if (!data || !table || !id) return null;
|
|
9
|
+
|
|
10
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
11
|
+
const { columns, pk } = await getMeta(table);
|
|
12
|
+
|
|
13
|
+
const names = columns?.map((el) => el.name);
|
|
14
|
+
const filterData = Object.keys(data)
|
|
15
|
+
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el)));
|
|
16
|
+
|
|
17
|
+
const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
18
|
+
|
|
19
|
+
const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`)).join(',')}
|
|
20
|
+
WHERE ${pk} = $1 returning *`;
|
|
21
|
+
// console.log(updateQuery, filterValue);
|
|
22
|
+
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
23
|
+
return res;
|
|
24
|
+
}
|
package/package.json
CHANGED
package/table/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import getTemplate from './controllers/utils/getTemplate.js';
|
|
|
11
11
|
import getSelect from './controllers/utils/getSelect.js';
|
|
12
12
|
|
|
13
13
|
const tableSchema = {
|
|
14
|
-
|
|
14
|
+
querystring1: {
|
|
15
15
|
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
16
16
|
order: { type: 'string', pattern: '^(\\d+)$' },
|
|
17
17
|
filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([\\w\\d_-]+)$' },
|
package/test/api/table.test.js
CHANGED
|
@@ -18,7 +18,7 @@ test('api table', async (t) => {
|
|
|
18
18
|
await t.test('GET /data (meta bbox / cls)', async () => {
|
|
19
19
|
const res = await app.inject({
|
|
20
20
|
method: 'GET',
|
|
21
|
-
url: `${config.prefix || '/api'}/data/test.dataset.table?bbox=${bbox}
|
|
21
|
+
url: `${config.prefix || '/api'}/data/test.dataset.table?bbox=${bbox}`,
|
|
22
22
|
});
|
|
23
23
|
const json = res.json();
|
|
24
24
|
assert.ok(json?.rows?.length === +count, 'meta bbox - not ok');
|