From 2b0f6afe4762926ec256636eb776a2b63882b42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Mon, 13 Nov 2023 15:33:45 +0000 Subject: [PATCH] chore: Modularise `/admin` endpoints, improve Feedback endpoint docs (#2413) --- .../admin/feedback/downloadFeedbackCSV.ts | 161 ------------------ api.planx.uk/modules/admin/controller.ts | 20 +++ api.planx.uk/modules/admin/docs.yaml | 28 +++ api.planx.uk/modules/admin/routes.ts | 37 ++++ .../feedback/downloadFeedbackCSV.test.ts | 14 +- .../service/feedback/downloadFeedbackCSV.ts | 85 +++++++++ .../modules/admin/service/feedback/types.ts | 63 +++++++ .../{ => modules}/admin/session/bops.test.ts | 6 +- .../{ => modules}/admin/session/bops.ts | 2 +- .../{ => modules}/admin/session/csv.test.ts | 4 +- .../{ => modules}/admin/session/csv.ts | 2 +- .../admin/session/digitalPlanningData.test.ts | 6 +- .../admin/session/digitalPlanningData.ts | 2 +- .../{ => modules}/admin/session/html.test.ts | 6 +- .../{ => modules}/admin/session/html.ts | 2 +- .../admin/session/oneAppXML.test.ts | 6 +- .../{ => modules}/admin/session/oneAppXML.ts | 2 +- .../admin/session/summary.test.ts | 6 +- .../{ => modules}/admin/session/summary.ts | 10 +- .../{ => modules}/admin/session/zip.test.ts | 6 +- .../{ => modules}/admin/session/zip.ts | 2 +- api.planx.uk/server.ts | 25 +-- 22 files changed, 278 insertions(+), 217 deletions(-) delete mode 100644 api.planx.uk/admin/feedback/downloadFeedbackCSV.ts create mode 100644 api.planx.uk/modules/admin/controller.ts create mode 100644 api.planx.uk/modules/admin/docs.yaml create mode 100644 api.planx.uk/modules/admin/routes.ts rename api.planx.uk/{admin => modules/admin/service}/feedback/downloadFeedbackCSV.test.ts (90%) create mode 100644 api.planx.uk/modules/admin/service/feedback/downloadFeedbackCSV.ts create mode 100644 api.planx.uk/modules/admin/service/feedback/types.ts rename api.planx.uk/{ => modules}/admin/session/bops.test.ts (88%) rename api.planx.uk/{ => modules}/admin/session/bops.ts (95%) rename api.planx.uk/{ => modules}/admin/session/csv.test.ts (95%) rename api.planx.uk/{ => modules}/admin/session/csv.ts (98%) rename api.planx.uk/{ => modules}/admin/session/digitalPlanningData.test.ts (88%) rename api.planx.uk/{ => modules}/admin/session/digitalPlanningData.ts (95%) rename api.planx.uk/{ => modules}/admin/session/html.test.ts (91%) rename api.planx.uk/{ => modules}/admin/session/html.ts (98%) rename api.planx.uk/{ => modules}/admin/session/oneAppXML.test.ts (90%) rename api.planx.uk/{ => modules}/admin/session/oneAppXML.ts (94%) rename api.planx.uk/{ => modules}/admin/session/summary.test.ts (88%) rename api.planx.uk/{ => modules}/admin/session/summary.ts (95%) rename api.planx.uk/{ => modules}/admin/session/zip.test.ts (88%) rename api.planx.uk/{ => modules}/admin/session/zip.ts (94%) diff --git a/api.planx.uk/admin/feedback/downloadFeedbackCSV.ts b/api.planx.uk/admin/feedback/downloadFeedbackCSV.ts deleted file mode 100644 index 6836fb37a8..0000000000 --- a/api.planx.uk/admin/feedback/downloadFeedbackCSV.ts +++ /dev/null @@ -1,161 +0,0 @@ -import { gql } from "graphql-request"; -import { Request, Response, NextFunction } from "express"; -import Axios from "axios"; -import { stringify } from "csv-stringify"; - -export interface Feedback { - id: number; - text: string; - category: string; - createdAt: string; - location: string; - screenshotUrl: string; - device: Device; - metadata?: Metadata[]; -} - -const METADATA_KEYS = [ - "address", - "uprn", - "title", - "data", - "service", - "team", - "component-metadata", - "reason", - "project-type", - "breadcrumbs", -] as const; - -type MetadataKey = (typeof METADATA_KEYS)[number]; - -interface Metadata { - key: MetadataKey; - value: string | Record; -} - -interface Device { - client: Client; - os: Os; -} - -interface Client { - name: string; - version: string; -} - -interface Os { - name: string; - version: string; -} - -type ParsedFeedback = Feedback & { - [key in MetadataKey]?: string | Record; -}; - -/** - * @swagger - * /admin/feedback: - * get: - * summary: Downloads the FeedbackFish CSV - * description: Downloads the FeedbackFish CSV - * tags: - * - admin - * security: - * - bearerAuth: [] - */ -export const downloadFeedbackCSV = async ( - req: Request, - res: Response, - next: NextFunction, -) => { - if (!req.query.cookie) - return next({ status: 401, message: "Missing cookie" }); - - try { - const feedback = await fetchFeedback(req.query.cookie as string); - const parsedFeedback = parseFeedback(feedback); - const csvStream = stringify(parsedFeedback, { - header: true, - columns: [ - "id", - "text", - "category", - "createdAt", - "location", - "screenshotUrl", - "device", - ...METADATA_KEYS, - ], - }); - res.header("Content-type", "text/csv"); - csvStream.pipe(res); - } catch (error) { - return next({ - message: - "Failed to generate FeedbackFish CSV: " + (error as Error).message, - }); - } -}; - -const fetchFeedback = async (cookie: string): Promise => { - const feedbackFishGraphQLEndpoint = "https://graphcdn.api.feedback.fish/"; - const body = { - query: gql` - query getFeedback($projectId: String!) { - feedback(projectId: $projectId) { - id - text - category - createdAt - location - screenshotUrl - metadata { - key - value - } - device { - client { - name - version - } - os { - name - version - } - } - } - } - `, - operationName: "getFeedback", - variables: { - projectId: "65f02de00b90d1", - }, - }; - - try { - const result = await Axios.post(feedbackFishGraphQLEndpoint, body, { - headers: { cookie }, - }); - const feedback: Feedback[] = result.data.data.feedback; - return feedback; - } catch (error) { - throw Error( - "Failed to connect to FeedbackFish: " + (error as Error).message, - ); - } -}; - -const generateMetadata = (feedback: ParsedFeedback): ParsedFeedback => { - // Transform metadata into kv pairs - feedback.metadata?.forEach(({ key, value }) => (feedback[key] = value)); - // Drop redundant raw metadata - delete feedback.metadata; - return feedback; -}; - -export const parseFeedback = (feedback: Feedback[]): ParsedFeedback[] => { - const parsedFeedback: ParsedFeedback[] = [...feedback]; - parsedFeedback.map(generateMetadata); - return parsedFeedback; -}; diff --git a/api.planx.uk/modules/admin/controller.ts b/api.planx.uk/modules/admin/controller.ts new file mode 100644 index 0000000000..62f8cd3484 --- /dev/null +++ b/api.planx.uk/modules/admin/controller.ts @@ -0,0 +1,20 @@ +import { generateFeedbackCSV } from "./service/feedback/downloadFeedbackCSV"; +import { DownloadFeedbackCSVController } from "./service/feedback/types"; + +export const downloadFeedbackCSV: DownloadFeedbackCSVController = async ( + req, + res, + next, +) => { + try { + const feedbackFishCookie = res.locals.parsedReq.query.cookie; + const csvStream = await generateFeedbackCSV(feedbackFishCookie); + res.header("Content-type", "text/csv"); + return csvStream.pipe(res); + } catch (error) { + return next({ + message: + "Failed to generate FeedbackFish CSV: " + (error as Error).message, + }); + } +}; diff --git a/api.planx.uk/modules/admin/docs.yaml b/api.planx.uk/modules/admin/docs.yaml new file mode 100644 index 0000000000..7404b0cad6 --- /dev/null +++ b/api.planx.uk/modules/admin/docs.yaml @@ -0,0 +1,28 @@ +openapi: 3.1.0 +info: + title: Planâś• API + version: 0.1.0 +tags: + - name: admin + description: Admin only utility endpoints +paths: + /admin/feedback: + get: + tags: ["admin"] + security: + - bearerAuth: [] + summary: Download FeedbackFish CSV + parameters: + - in: query + name: cookie + type: string + description: Cookie from FeedbackFish to authenticate request + required: true + responses: + "200": + content: + text/csv: + schema: + type: string + "500": + $ref: "#/components/responses/ErrorMessage" diff --git a/api.planx.uk/modules/admin/routes.ts b/api.planx.uk/modules/admin/routes.ts new file mode 100644 index 0000000000..ced4e2dfdf --- /dev/null +++ b/api.planx.uk/modules/admin/routes.ts @@ -0,0 +1,37 @@ +import { Router } from "express"; +import { usePlatformAdminAuth } from "../auth/middleware"; +import { getOneAppXML } from "./session/oneAppXML"; +import { getBOPSPayload } from "./session/bops"; +import { getCSVData, getRedactedCSVData } from "./session/csv"; +import { getHTMLExport, getRedactedHTMLExport } from "./session/html"; +import { generateZip } from "./session/zip"; +import { getSessionSummary } from "./session/summary"; +import { getDigitalPlanningApplicationPayload } from "./session/digitalPlanningData"; +import { validate } from "../../shared/middleware/validate"; +import { downloadFeedbackCSVSchema } from "./service/feedback/types"; +import { downloadFeedbackCSV } from "./controller"; + +const router = Router(); + +router.use(usePlatformAdminAuth); +router.get( + "/feedback", + validate(downloadFeedbackCSVSchema), + downloadFeedbackCSV, +); + +// TODO: Split the routes below into controller and service components +router.get("/session/:sessionId/xml", getOneAppXML); +router.get("/session/:sessionId/bops", getBOPSPayload); +router.get("/session/:sessionId/csv", getCSVData); +router.get("/session/:sessionId/csv-redacted", getRedactedCSVData); +router.get("/session/:sessionId/html", getHTMLExport); +router.get("/session/:sessionId/html-redacted", getRedactedHTMLExport); +router.get("/session/:sessionId/zip", generateZip); +router.get("/session/:sessionId/summary", getSessionSummary); +router.get( + "/session/:sessionId/digital-planning-application", + getDigitalPlanningApplicationPayload, +); + +export default router; diff --git a/api.planx.uk/admin/feedback/downloadFeedbackCSV.test.ts b/api.planx.uk/modules/admin/service/feedback/downloadFeedbackCSV.test.ts similarity index 90% rename from api.planx.uk/admin/feedback/downloadFeedbackCSV.test.ts rename to api.planx.uk/modules/admin/service/feedback/downloadFeedbackCSV.test.ts index 82d010aad4..508baac373 100644 --- a/api.planx.uk/admin/feedback/downloadFeedbackCSV.test.ts +++ b/api.planx.uk/modules/admin/service/feedback/downloadFeedbackCSV.test.ts @@ -1,8 +1,9 @@ -import { Feedback, parseFeedback } from "./downloadFeedbackCSV"; +import { parseFeedback } from "./downloadFeedbackCSV"; import supertest from "supertest"; -import app from "../../server"; -import { authHeader } from "../../tests/mockJWT"; +import app from "../../../../server"; +import { authHeader } from "../../../../tests/mockJWT"; import Axios from "axios"; +import { Feedback } from "./types"; jest.mock("axios"); const mockAxios = Axios as jest.Mocked; @@ -72,8 +73,11 @@ describe("Download feedback CSV endpoint", () => { await supertest(app) .get(ENDPOINT) .set(auth) - .expect(401) - .then((res) => expect(res.body).toEqual({ error: "Missing cookie" })); + .expect(400) + .then((res) => { + expect(res.body).toHaveProperty("issues"); + expect(res.body).toHaveProperty("name", "ZodError"); + }); }); it("returns an error if request to FeedbackFish fails", async () => { diff --git a/api.planx.uk/modules/admin/service/feedback/downloadFeedbackCSV.ts b/api.planx.uk/modules/admin/service/feedback/downloadFeedbackCSV.ts new file mode 100644 index 0000000000..022270e31b --- /dev/null +++ b/api.planx.uk/modules/admin/service/feedback/downloadFeedbackCSV.ts @@ -0,0 +1,85 @@ +import { gql } from "graphql-request"; +import Axios from "axios"; +import { stringify } from "csv-stringify"; +import { Feedback, METADATA_KEYS, ParsedFeedback } from "./types"; + +export const generateFeedbackCSV = async (feedbackFishCookie: string) => { + const feedback = await fetchFeedback(feedbackFishCookie); + const parsedFeedback = parseFeedback(feedback); + const csvStream = stringify(parsedFeedback, { + header: true, + columns: [ + "id", + "text", + "category", + "createdAt", + "location", + "screenshotUrl", + "device", + ...METADATA_KEYS, + ], + }); + return csvStream; +}; + +const fetchFeedback = async (cookie: string): Promise => { + const feedbackFishGraphQLEndpoint = "https://graphcdn.api.feedback.fish/"; + const body = { + query: gql` + query getFeedback($projectId: String!) { + feedback(projectId: $projectId) { + id + text + category + createdAt + location + screenshotUrl + metadata { + key + value + } + device { + client { + name + version + } + os { + name + version + } + } + } + } + `, + operationName: "getFeedback", + variables: { + projectId: "65f02de00b90d1", + }, + }; + + try { + const result = await Axios.post(feedbackFishGraphQLEndpoint, body, { + headers: { cookie }, + }); + const feedback: Feedback[] = result.data.data.feedback; + return feedback; + } catch (error) { + throw Error( + "Failed to connect to FeedbackFish: " + (error as Error).message, + ); + } +}; + +const generateMetadata = (feedback: ParsedFeedback): ParsedFeedback => { + // Transform metadata into kv pairs + feedback.metadata?.forEach(({ key, value }) => (feedback[key] = value)); + // Drop redundant raw metadata + delete feedback.metadata; + return feedback; +}; + +export const parseFeedback = (feedback: Feedback[]): ParsedFeedback[] => { + const parsedFeedback: ParsedFeedback[] = [...feedback]; + parsedFeedback.map(generateMetadata); + return parsedFeedback; +}; diff --git a/api.planx.uk/modules/admin/service/feedback/types.ts b/api.planx.uk/modules/admin/service/feedback/types.ts new file mode 100644 index 0000000000..00ac41afe5 --- /dev/null +++ b/api.planx.uk/modules/admin/service/feedback/types.ts @@ -0,0 +1,63 @@ +import { ValidatedRequestHandler } from "../../../../shared/middleware/validate"; +import { z } from "zod"; + +export interface Feedback { + id: number; + text: string; + category: string; + createdAt: string; + location: string; + screenshotUrl: string; + device: Device; + metadata?: Metadata[]; +} + +export const METADATA_KEYS = [ + "address", + "uprn", + "title", + "data", + "service", + "team", + "component-metadata", + "reason", + "project-type", + "breadcrumbs", +] as const; + +export type MetadataKey = (typeof METADATA_KEYS)[number]; + +export interface Metadata { + key: MetadataKey; + value: string | Record; +} + +export interface Device { + client: Client; + os: Os; +} + +export interface Client { + name: string; + version: string; +} + +export interface Os { + name: string; + version: string; +} + +export type ParsedFeedback = Feedback & { + [key in MetadataKey]?: string | Record; +}; + +export const downloadFeedbackCSVSchema = z.object({ + query: z.object({ + cookie: z.string(), + }), +}); + +export type DownloadFeedbackCSVController = ValidatedRequestHandler< + typeof downloadFeedbackCSVSchema, + NodeJS.ReadableStream +>; diff --git a/api.planx.uk/admin/session/bops.test.ts b/api.planx.uk/modules/admin/session/bops.test.ts similarity index 88% rename from api.planx.uk/admin/session/bops.test.ts rename to api.planx.uk/modules/admin/session/bops.test.ts index 5665ae9c09..f4441e20dc 100644 --- a/api.planx.uk/admin/session/bops.test.ts +++ b/api.planx.uk/modules/admin/session/bops.test.ts @@ -1,7 +1,7 @@ import supertest from "supertest"; -import app from "../../server"; -import { authHeader } from "../../tests/mockJWT"; -import { expectedPayload } from "../../tests/mocks/bopsMocks"; +import app from "../../../server"; +import { authHeader } from "../../../tests/mockJWT"; +import { expectedPayload } from "../../../tests/mocks/bopsMocks"; const endpoint = (strings: TemplateStringsArray) => `/admin/session/${strings[0]}/bops`; diff --git a/api.planx.uk/admin/session/bops.ts b/api.planx.uk/modules/admin/session/bops.ts similarity index 95% rename from api.planx.uk/admin/session/bops.ts rename to api.planx.uk/modules/admin/session/bops.ts index 09a44a43c2..bba3a61432 100644 --- a/api.planx.uk/admin/session/bops.ts +++ b/api.planx.uk/modules/admin/session/bops.ts @@ -1,5 +1,5 @@ import { NextFunction, Request, Response } from "express"; -import { $api } from "../../client"; +import { $api } from "../../../client"; /** * @swagger diff --git a/api.planx.uk/admin/session/csv.test.ts b/api.planx.uk/modules/admin/session/csv.test.ts similarity index 95% rename from api.planx.uk/admin/session/csv.test.ts rename to api.planx.uk/modules/admin/session/csv.test.ts index a40152a272..601231ffc2 100644 --- a/api.planx.uk/admin/session/csv.test.ts +++ b/api.planx.uk/modules/admin/session/csv.test.ts @@ -1,6 +1,6 @@ import supertest from "supertest"; -import app from "../../server"; -import { authHeader } from "../../tests/mockJWT"; +import app from "../../../server"; +import { authHeader } from "../../../tests/mockJWT"; const endpoint = (strings: TemplateStringsArray) => `/admin/session/${strings[0]}/csv`; diff --git a/api.planx.uk/admin/session/csv.ts b/api.planx.uk/modules/admin/session/csv.ts similarity index 98% rename from api.planx.uk/admin/session/csv.ts rename to api.planx.uk/modules/admin/session/csv.ts index c0c3f2f1c0..974db8808e 100644 --- a/api.planx.uk/admin/session/csv.ts +++ b/api.planx.uk/modules/admin/session/csv.ts @@ -1,6 +1,6 @@ import { stringify } from "csv-stringify"; import { NextFunction, Request, Response } from "express"; -import { $api } from "../../client"; +import { $api } from "../../../client"; /** * @swagger diff --git a/api.planx.uk/admin/session/digitalPlanningData.test.ts b/api.planx.uk/modules/admin/session/digitalPlanningData.test.ts similarity index 88% rename from api.planx.uk/admin/session/digitalPlanningData.test.ts rename to api.planx.uk/modules/admin/session/digitalPlanningData.test.ts index 254a0ab8c8..09d3f114c9 100644 --- a/api.planx.uk/admin/session/digitalPlanningData.test.ts +++ b/api.planx.uk/modules/admin/session/digitalPlanningData.test.ts @@ -1,7 +1,7 @@ import supertest from "supertest"; -import app from "../../server"; -import { authHeader } from "../../tests/mockJWT"; -import { expectedPlanningPermissionPayload } from "../../tests/mocks/digitalPlanningDataMocks"; +import app from "../../../server"; +import { authHeader } from "../../../tests/mockJWT"; +import { expectedPlanningPermissionPayload } from "../../../tests/mocks/digitalPlanningDataMocks"; const endpoint = (strings: TemplateStringsArray) => `/admin/session/${strings[0]}/digital-planning-application`; diff --git a/api.planx.uk/admin/session/digitalPlanningData.ts b/api.planx.uk/modules/admin/session/digitalPlanningData.ts similarity index 95% rename from api.planx.uk/admin/session/digitalPlanningData.ts rename to api.planx.uk/modules/admin/session/digitalPlanningData.ts index 76929647ba..eb76b97d0c 100644 --- a/api.planx.uk/admin/session/digitalPlanningData.ts +++ b/api.planx.uk/modules/admin/session/digitalPlanningData.ts @@ -1,5 +1,5 @@ import { NextFunction, Request, Response } from "express"; -import { $api } from "../../client"; +import { $api } from "../../../client"; /** * @swagger diff --git a/api.planx.uk/admin/session/html.test.ts b/api.planx.uk/modules/admin/session/html.test.ts similarity index 91% rename from api.planx.uk/admin/session/html.test.ts rename to api.planx.uk/modules/admin/session/html.test.ts index 3a35a62319..24dc985bbd 100644 --- a/api.planx.uk/admin/session/html.test.ts +++ b/api.planx.uk/modules/admin/session/html.test.ts @@ -1,6 +1,6 @@ import supertest from "supertest"; -import app from "../../server"; -import { authHeader } from "../../tests/mockJWT"; +import app from "../../../server"; +import { authHeader } from "../../../tests/mockJWT"; const endpoint = (strings: TemplateStringsArray) => `/admin/session/${strings[0]}/html`; @@ -15,7 +15,7 @@ const mockGenerateHTMLData = jest.fn().mockResolvedValue({ ], redactedResponses: [], }); -jest.mock("../../client", () => { +jest.mock("../../../client", () => { return { $api: { export: { diff --git a/api.planx.uk/admin/session/html.ts b/api.planx.uk/modules/admin/session/html.ts similarity index 98% rename from api.planx.uk/admin/session/html.ts rename to api.planx.uk/modules/admin/session/html.ts index e6c88eba1a..8fe049d8eb 100644 --- a/api.planx.uk/admin/session/html.ts +++ b/api.planx.uk/modules/admin/session/html.ts @@ -1,5 +1,5 @@ import { generateApplicationHTML } from "@opensystemslab/planx-core"; -import { $api } from "../../client"; +import { $api } from "../../../client"; import type { RequestHandler } from "express"; import type { PlanXExportData } from "@opensystemslab/planx-core/types"; diff --git a/api.planx.uk/admin/session/oneAppXML.test.ts b/api.planx.uk/modules/admin/session/oneAppXML.test.ts similarity index 90% rename from api.planx.uk/admin/session/oneAppXML.test.ts rename to api.planx.uk/modules/admin/session/oneAppXML.test.ts index 4b8dc3bfe3..5988ba1778 100644 --- a/api.planx.uk/admin/session/oneAppXML.test.ts +++ b/api.planx.uk/modules/admin/session/oneAppXML.test.ts @@ -1,6 +1,6 @@ import supertest from "supertest"; -import app from "../../server"; -import { authHeader } from "../../tests/mockJWT"; +import app from "../../../server"; +import { authHeader } from "../../../tests/mockJWT"; const endpoint = (strings: TemplateStringsArray) => `/admin/session/${strings[0]}/xml`; @@ -9,7 +9,7 @@ const mockGenerateOneAppXML = jest .fn() .mockResolvedValue(""); -jest.mock("../../client", () => { +jest.mock("../../../client", () => { return { $api: { export: { diff --git a/api.planx.uk/admin/session/oneAppXML.ts b/api.planx.uk/modules/admin/session/oneAppXML.ts similarity index 94% rename from api.planx.uk/admin/session/oneAppXML.ts rename to api.planx.uk/modules/admin/session/oneAppXML.ts index 7b1ef90601..55985ec42e 100644 --- a/api.planx.uk/admin/session/oneAppXML.ts +++ b/api.planx.uk/modules/admin/session/oneAppXML.ts @@ -1,5 +1,5 @@ import { Request, Response, NextFunction } from "express"; -import { $api } from "../../client"; +import { $api } from "../../../client"; /** * @swagger diff --git a/api.planx.uk/admin/session/summary.test.ts b/api.planx.uk/modules/admin/session/summary.test.ts similarity index 88% rename from api.planx.uk/admin/session/summary.test.ts rename to api.planx.uk/modules/admin/session/summary.test.ts index 08c7b2b838..a74cbd9844 100644 --- a/api.planx.uk/admin/session/summary.test.ts +++ b/api.planx.uk/modules/admin/session/summary.test.ts @@ -1,7 +1,7 @@ import supertest from "supertest"; -import app from "../../server"; -import { queryMock } from "../../tests/graphqlQueryMock"; -import { authHeader } from "../../tests/mockJWT"; +import app from "../../../server"; +import { queryMock } from "../../../tests/graphqlQueryMock"; +import { authHeader } from "../../../tests/mockJWT"; const endpoint = (strings: TemplateStringsArray) => `/admin/session/${strings[0]}/summary`; diff --git a/api.planx.uk/admin/session/summary.ts b/api.planx.uk/modules/admin/session/summary.ts similarity index 95% rename from api.planx.uk/admin/session/summary.ts rename to api.planx.uk/modules/admin/session/summary.ts index 344a6c283b..9139719bc5 100644 --- a/api.planx.uk/admin/session/summary.ts +++ b/api.planx.uk/modules/admin/session/summary.ts @@ -6,8 +6,14 @@ import { import { NextFunction, Request, Response } from "express"; import { gql } from "graphql-request"; -import { Breadcrumb, Flow, LowCalSession, Passport, Team } from "../../types"; -import { $api } from "../../client"; +import { + Breadcrumb, + Flow, + LowCalSession, + Passport, + Team, +} from "../../../types"; +import { $api } from "../../../client"; /** * @swagger diff --git a/api.planx.uk/admin/session/zip.test.ts b/api.planx.uk/modules/admin/session/zip.test.ts similarity index 88% rename from api.planx.uk/admin/session/zip.test.ts rename to api.planx.uk/modules/admin/session/zip.test.ts index 9e7e6d5979..8bccccfbe3 100644 --- a/api.planx.uk/admin/session/zip.test.ts +++ b/api.planx.uk/modules/admin/session/zip.test.ts @@ -1,8 +1,8 @@ import supertest from "supertest"; -import app from "../../server"; -import { authHeader } from "../../tests/mockJWT"; +import app from "../../../server"; +import { authHeader } from "../../../tests/mockJWT"; -jest.mock("../../send/exportZip", () => ({ +jest.mock("../../../send/exportZip", () => ({ buildSubmissionExportZip: jest.fn().mockResolvedValue({ filename: "tests/mocks/test.zip", remove: jest.fn, diff --git a/api.planx.uk/admin/session/zip.ts b/api.planx.uk/modules/admin/session/zip.ts similarity index 94% rename from api.planx.uk/admin/session/zip.ts rename to api.planx.uk/modules/admin/session/zip.ts index e57179807f..233392793d 100644 --- a/api.planx.uk/admin/session/zip.ts +++ b/api.planx.uk/modules/admin/session/zip.ts @@ -1,5 +1,5 @@ import { NextFunction, Request, Response } from "express"; -import { buildSubmissionExportZip } from "../../send/exportZip"; +import { buildSubmissionExportZip } from "../../../send/exportZip"; /** * @swagger diff --git a/api.planx.uk/server.ts b/api.planx.uk/server.ts index afbc99655a..88e608363a 100644 --- a/api.planx.uk/server.ts +++ b/api.planx.uk/server.ts @@ -54,15 +54,8 @@ import { sendToUniform } from "./send/uniform"; import { copyFlow } from "./editor/copyFlow"; import { moveFlow } from "./editor/moveFlow"; import { useOrdnanceSurveyProxy } from "./proxy/ordnanceSurvey"; -import { downloadFeedbackCSV } from "./admin/feedback/downloadFeedbackCSV"; -import { getOneAppXML } from "./admin/session/oneAppXML"; import { gql } from "graphql-request"; import { classifiedRoadsSearch } from "./gis/classifiedRoads"; -import { getBOPSPayload } from "./admin/session/bops"; -import { getCSVData, getRedactedCSVData } from "./admin/session/csv"; -import { getHTMLExport, getRedactedHTMLExport } from "./admin/session/html"; -import { generateZip } from "./admin/session/zip"; -import { getSessionSummary } from "./admin/session/summary"; import { googleStrategy } from "./modules/auth/strategy/google"; import authRoutes from "./modules/auth/routes"; import teamRoutes from "./modules/team/routes"; @@ -70,9 +63,9 @@ import miscRoutes from "./modules/misc/routes"; import userRoutes from "./modules/user/routes"; import webhookRoutes from "./modules/webhooks/routes"; import analyticsRoutes from "./modules/analytics/routes"; +import adminRoutes from "./modules/admin/routes"; import { useSwaggerDocs } from "./docs"; import { Role } from "@opensystemslab/planx-core/types"; -import { getDigitalPlanningApplicationPayload } from "./admin/session/digitalPlanningData"; import { $public } from "./client"; const router = express.Router(); @@ -190,6 +183,7 @@ app.use("/user", userRoutes); app.use("/team", teamRoutes); app.use("/webhooks", webhookRoutes); app.use("/analytics", analyticsRoutes); +app.use("/admin", adminRoutes); app.use("/gis", router); @@ -204,21 +198,6 @@ app.get("/gis/:localAuthority", locationSearch); app.get("/roads", classifiedRoadsSearch); -app.use("/admin", usePlatformAdminAuth); -app.get("/admin/feedback", downloadFeedbackCSV); -app.get("/admin/session/:sessionId/xml", getOneAppXML); -app.get("/admin/session/:sessionId/bops", getBOPSPayload); -app.get("/admin/session/:sessionId/csv", getCSVData); -app.get("/admin/session/:sessionId/csv-redacted", getRedactedCSVData); -app.get("/admin/session/:sessionId/html", getHTMLExport); -app.get("/admin/session/:sessionId/html-redacted", getRedactedHTMLExport); -app.get("/admin/session/:sessionId/zip", generateZip); -app.get("/admin/session/:sessionId/summary", getSessionSummary); -app.get( - "/admin/session/:sessionId/digital-planning-application", - getDigitalPlanningApplicationPayload, -); - app.post("/flows/:flowId/copy", useTeamEditorAuth, copyFlow); app.post("/flows/:flowId/diff", useTeamEditorAuth, validateAndDiffFlow);