From e12ddcaa6558b1d7cd1588e4e7badeae5028c94d Mon Sep 17 00:00:00 2001 From: lambeb <141648830+lambeb@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:38:51 +0000 Subject: [PATCH] Cleaned up some code to be more generic --- src/server/handlers/cloudFunctionHandler.ts | 16 ++++++++-------- src/server/server.ts | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/server/handlers/cloudFunctionHandler.ts b/src/server/handlers/cloudFunctionHandler.ts index 8ac31563..2fb9376c 100644 --- a/src/server/handlers/cloudFunctionHandler.ts +++ b/src/server/handlers/cloudFunctionHandler.ts @@ -1,12 +1,12 @@ import express, { Request, Response, Router } from "express"; import { callCloudFunction } from "../helpers/cloudFunctionCallerHelper"; -export default function newCloudFunctionHandler( - CreateDonorCasesCloudFunctionUrl: string +export default function createDonorCasesCloudFunctionHandler( + CloudFunctionUrl: string ): Router { const router = express.Router(); const cloudFunctionHandler = new CloudFunctionHandler( - CreateDonorCasesCloudFunctionUrl + CloudFunctionUrl ); router.post("/api/cloudFunction/createDonorCases", cloudFunctionHandler.CallCloudFunction); @@ -28,17 +28,17 @@ export function reissueNewDonorCaseCloudFunctionHandler( export class CloudFunctionHandler { CloudFunctionUrl: string; - constructor(CreateDonorCasesCloudFunctionUrl: string) { - this.CloudFunctionUrl = CreateDonorCasesCloudFunctionUrl; + constructor(CloudFunctionUrl: string) { + this.CloudFunctionUrl = CloudFunctionUrl; this.CallCloudFunction = this.CallCloudFunction.bind(this); } async CallCloudFunction(req: Request, res: Response): Promise { const reqData = req.body; - req.log.info(`${this.CloudFunctionUrl} URL to invoke for Creating Donor Cases.`); + req.log.info(`${this.CloudFunctionUrl} URL to invoke for Cloud Function.`); try { - const cloudfunctionResponse = await callCloudFunction(this.CloudFunctionUrl, reqData); - return res.status(cloudfunctionResponse.status).json(cloudfunctionResponse); + const cloudFunctionResponse = await callCloudFunction(this.CloudFunctionUrl, reqData); + return res.status(cloudFunctionResponse.status).json(cloudFunctionResponse); } catch (error) { console.error("Error:", error); diff --git a/src/server/server.ts b/src/server/server.ts index c048de2d..066a6936 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -17,7 +17,7 @@ import createLogger from "./pino"; import { HttpLogger } from "pino-http"; import AuditLogger from "./auditLogging/logger"; import newAuditHandler from "./handlers/auditHandler"; -import newCloudFunctionHandler from "./handlers/cloudFunctionHandler"; +import createDonorCasesCloudFunctionHandler from "./handlers/cloudFunctionHandler"; import { reissueNewDonorCaseCloudFunctionHandler } from "./handlers/cloudFunctionHandler"; if (process.env.NODE_ENV === "production") { @@ -45,7 +45,7 @@ export function newServer(config: Config, logger: HttpLogger = createLogger()): const busHandler = newBusHandler(busApiClient, auth); const uploadHandler = newUploadHandler(storageManager, auth, auditLogger); const auditHandler = newAuditHandler(auditLogger); - const cloudFunctionHandler = newCloudFunctionHandler(config.CreateDonorCasesCloudFunctionUrl); + const createDonorCasesHandler = createDonorCasesCloudFunctionHandler(config.CreateDonorCasesCloudFunctionUrl); const reissueNewDonorCaseHandler = reissueNewDonorCaseCloudFunctionHandler(config.ReissueNewDonorCaseCloudFunctionUrl); const server = express(); @@ -72,7 +72,7 @@ export function newServer(config: Config, logger: HttpLogger = createLogger()): server.use("/", bimsHandler); server.use("/", busHandler); server.use("/", auditHandler); - server.use("/", cloudFunctionHandler); + server.use("/", createDonorCasesHandler); server.use("/", reissueNewDonorCaseHandler); server.use("/", HealthCheckHandler());