Skip to content

Commit

Permalink
Cleaned up some code to be more generic
Browse files Browse the repository at this point in the history
lambeb committed Oct 29, 2024

Verified

This commit was signed with the committer’s verified signature.
lambeb BenjaminLambe_ONS
1 parent 6effcf3 commit e12ddca
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/server/handlers/cloudFunctionHandler.ts
Original file line number Diff line number Diff line change
@@ -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<Response> {
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);
6 changes: 3 additions & 3 deletions src/server/server.ts
Original file line number Diff line number Diff line change
@@ -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());

0 comments on commit e12ddca

Please sign in to comment.