Skip to content

Commit

Permalink
chore: Move GIS to module, setup routes
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 17, 2023
1 parent 44a5be8 commit 5d6bf76
Show file tree
Hide file tree
Showing 23 changed files with 20 additions and 25 deletions.
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 Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { gql } from "graphql-request";
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
File renamed without changes.
File renamed without changes.
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

0 comments on commit 5d6bf76

Please sign in to comment.