refactor
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const express = require("express");
|
||||
const db = require("../db/polygons");
|
||||
const { normalizeFeatureCollectionContract, normalizeFeatureContract } = require("../types/contracts");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -70,13 +71,13 @@ router.get("/", (req, res) => {
|
||||
const geometryIds = rows.map((row) => String(row.id));
|
||||
const linksByGeometryId = loadGeometryLinksByGeometryId(geometryIds);
|
||||
|
||||
res.json({
|
||||
res.json(normalizeFeatureCollectionContract({
|
||||
type: "FeatureCollection",
|
||||
features: rows.map((row) => {
|
||||
const linkedEntities = linksByGeometryId.get(String(row.id)) || [];
|
||||
return buildFeatureFromRow(row, linkedEntities);
|
||||
}),
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -95,7 +96,7 @@ function buildFeatureFromRow(row, linkedEntities = []) {
|
||||
? storedGeometryType
|
||||
: normalizeGeometryType(primaryEntity?.entity_type_id);
|
||||
|
||||
return {
|
||||
return normalizeFeatureContract({
|
||||
type: "Feature",
|
||||
properties: {
|
||||
id: row.id,
|
||||
@@ -112,7 +113,7 @@ function buildFeatureFromRow(row, linkedEntities = []) {
|
||||
entity_type_id: primaryEntity?.entity_type_id || null,
|
||||
},
|
||||
geometry: JSON.parse(row.draw_geometry),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeGeometryType(value) {
|
||||
|
||||
Reference in New Issue
Block a user