Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Move GIS to module, setup routes #2446

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api.planx.uk/modules/gis/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from "express";
import { locationSearch } from "./service";
import { classifiedRoadsSearch } from "./service/classifiedRoads";

const router = Router();

router.get("/gis/:localAuthority", locationSearch);
router.get("/roads", classifiedRoadsSearch);

export default router;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import supertest from "supertest";

import loadOrRecordNockRequests from "../tests/loadOrRecordNockRequests";
import app from "../server";
import loadOrRecordNockRequests from "../../../tests/loadOrRecordNockRequests";
import app from "../../../server";
import { PASSPORT_FN } from "./classifiedRoads";

it("returns an error if required query param is missing", async () => {
Expand All @@ -17,7 +17,7 @@

// "Success" test commented out due to reliance on external API calls and fallibility of nocks
// Please comment in and run locally if making changes to /roads functionality
describe.skip("fetching classified roads data from OS Features API for any local authority", () => {

Check warning on line 20 in api.planx.uk/modules/gis/service/classifiedRoads.test.ts

View workflow job for this annotation

GitHub Actions / Run API Tests

Disabled test suite
jest.setTimeout(10000);

// address is for reference only, geom is buffered & flipped site boundary coords
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import fetch from "isomorphic-fetch";
import { addDesignatedVariable, omitGeometry } from "./helpers";
import { baseSchema } from "./local_authorities/metadata/base";
import { $api } from "../client";
import { $api } from "../../../client";

export interface LocalAuthorityMetadata {
planningConstraints: {
Expand Down Expand Up @@ -68,8 +68,8 @@
options,
)}${datasets}`;
const res = await fetch(url)
.then((response: { json: () => any }) => response.json())

Check warning on line 71 in api.planx.uk/modules/gis/service/digitalLand.ts

View workflow job for this annotation

GitHub Actions / Run API Tests

Unexpected any. Specify a different type
.catch((error: any) => console.log(error));

Check warning on line 72 in api.planx.uk/modules/gis/service/digitalLand.ts

View workflow job for this annotation

GitHub Actions / Run API Tests

Unexpected any. Specify a different type

// if analytics are "on", store an audit record of the raw response
if (extras?.analytics !== "false") {
Expand Down Expand Up @@ -103,7 +103,7 @@
// check for & add any 'positive' constraints to the formattedResult
let formattedResult: Record<string, Constraint> = {};
if (res && res.count > 0 && res.entities) {
res.entities.forEach((entity: { dataset: any }) => {

Check warning on line 106 in api.planx.uk/modules/gis/service/digitalLand.ts

View workflow job for this annotation

GitHub Actions / Run API Tests

Unexpected any. Specify a different type
// get the planx variable that corresponds to this entity's 'dataset', should never be null because our initial request is filtered on 'dataset'
const key = Object.keys(baseSchema).find(
(key) =>
Expand Down Expand Up @@ -152,7 +152,7 @@
formattedResult["designated.nationalPark"] &&
formattedResult["designated.nationalPark"].value
) {
formattedResult["designated.nationalPark"]?.data?.forEach((entity: any) => {

Check warning on line 155 in api.planx.uk/modules/gis/service/digitalLand.ts

View workflow job for this annotation

GitHub Actions / Run API Tests

Unexpected any. Specify a different type
if (
baseSchema[broads]["digital-land-entities"]?.includes(entity.entity)
) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import supertest from "supertest";

import { locationSearchWithTimeout } from "../gis";
import loadOrRecordNockRequests from "../tests/loadOrRecordNockRequests";
import app from "../server";
import loadOrRecordNockRequests from "../../../tests/loadOrRecordNockRequests";
import app from "../../../server";
import { locationSearchWithTimeout } from ".";

// Tests commented out due to reliance on external API calls and fallibility of nocks
// Please comment in and run locally if making changes to /gis functionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
rollupResultLayers,
addDesignatedVariable,
} from "../helpers.js";
import { planningConstraints } from "./metadata/scotland";
import { planningConstraints } from "./metadata/scotland.js";

// Process local authority metadata
const gisLayers = getQueryableConstraints(planningConstraints);
Expand Down
19 changes: 2 additions & 17 deletions api.planx.uk/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import passport from "passport";
import helmet from "helmet";

import { ServerError } from "./errors";
import { locationSearch } from "./gis/index";
import {
makePaymentViaProxy,
fetchPaymentViaProxy,
Expand All @@ -33,7 +32,6 @@ import { sendToBOPS } from "./send/bops";
import { createSendEvents } from "./send/createSendEvents";
import { downloadApplicationFiles, sendToEmail } from "./send/email";
import { sendToUniform } from "./send/uniform";
import { classifiedRoadsSearch } from "./gis/classifiedRoads";
import { googleStrategy } from "./modules/auth/strategy/google";
import authRoutes from "./modules/auth/routes";
import teamRoutes from "./modules/team/routes";
Expand All @@ -47,11 +45,10 @@ import ordnanceSurveyRoutes from "./modules/ordnanceSurvey/routes";
import saveAndReturnRoutes from "./modules/saveAndReturn/routes";
import sendEmailRoutes from "./modules/sendEmail/routes";
import fileRoutes from "./modules/file/routes";
import gisRoutes from "./modules/gis/routes";
import { useSwaggerDocs } from "./docs";
import { Role } from "@opensystemslab/planx-core/types";

const router = express.Router();

const app = express();

useSwaggerDocs(app);
Expand Down Expand Up @@ -172,19 +169,7 @@ app.use("/file", fileRoutes);
app.use(saveAndReturnRoutes);
app.use(sendEmailRoutes);
app.use("/flows", flowRoutes);

app.use("/gis", router);

app.get("/gis", (_req, _res, next) => {
next({
status: 400,
message: "Please specify a local authority",
});
});

app.get("/gis/:localAuthority", locationSearch);

app.get("/roads", classifiedRoadsSearch);
app.use(gisRoutes);

// allows an applicant to download their application data on the Confirmation page
app.post("/download-application", async (req, res, next) => {
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/tests/serverErrorHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("bad requests", () => {
});

test(`app.get("/gis")`, async () => {
await get("/gis").expect(400);
await get("/gis").expect(404);
});

test(`app.get("/gis/wrong")`, async () => {
Expand Down
Loading