Skip to content

Commit

Permalink
chore: set new exclude_field query param on Planning Data requests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Aug 6, 2024
1 parent 4c58119 commit 907d282
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 47 deletions.
7 changes: 4 additions & 3 deletions api.planx.uk/modules/gis/service/digitalLand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from "@opensystemslab/planx-core/types";
import { gql } from "graphql-request";
import fetch from "isomorphic-fetch";
import { addDesignatedVariable, omitGeometry } from "./helpers";
import { addDesignatedVariable } from "./helpers";
import { baseSchema } from "./local_authorities/metadata/base";
import { $api } from "../../../client";

Expand Down Expand Up @@ -68,6 +68,7 @@ async function go(
entries: "current",
geometry: geom,
geometry_relation: "intersects",
exclude_field: "geometry,point",
limit: "100", // TODO handle pagination in future for large polygons & many datasets, but should be well within this limit now
};
// 'dataset' param is not array[string] per docs, instead re-specify param name per unique dataset
Expand Down Expand Up @@ -120,14 +121,14 @@ async function go(
);
// because there can be many digital land datasets per planx variable, check if this key is already in our result
if (key && Object.keys(formattedResult).includes(key)) {
formattedResult[key]["data"]?.push(omitGeometry(entity));
formattedResult[key]["data"]?.push(entity);
} else {
if (key) {
formattedResult[key] = {
fn: key,
value: true,
text: baseSchema[key].pos,
data: [omitGeometry(entity)],
data: [entity],
category: baseSchema[key].category,
};
}
Expand Down
11 changes: 0 additions & 11 deletions api.planx.uk/modules/gis/service/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,6 @@ const getA4Subvariables = (features, articleFours, a4Key) => {
return result;
};

// Filter a Digital Land entity response object, omitting the "geometry" & "point" keys if exists
const omitGeometry = (entity) => {
return Object.keys(entity)
.filter((key) => !["geometry", "point"].includes(key))
.reduce((obj, key) => {
obj[key] = entity[key];
return obj;
}, {});
};

export {
setEsriGeometryType,
setEsriGeometry,
Expand All @@ -219,6 +209,5 @@ export {
squashResultLayers,
rollupResultLayers,
getA4Subvariables,
omitGeometry,
addDesignatedVariable,
};
Loading

0 comments on commit 907d282

Please sign in to comment.