Skip to content

Commit

Permalink
fetch lab data
Browse files Browse the repository at this point in the history
  • Loading branch information
kr1s-r committed Nov 27, 2024
1 parent eaa6427 commit 3908dc1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/server/src/controllers/routeControllers/lap.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { BackendController } from "../BackendController/BackendController";

import { type Request, type Response } from "express";

import { createApplicationLogger } from "@/utils/logger";

export const getLapData = async (request: Request, response: Response) => {
const backendController = request.app.locals
.backendController as BackendController;

const logger = createApplicationLogger(
"lap.controller.ts",
request,
response,
);

try {
const timestamp = new Date(request.params.timestamp);
const lapData = await backendController.dynamoDB.getPacketData(timestamp);

logger.info(`ENTRY - ${request.method} ${request.url}`);
const data = {
data: lapData,
message: "OK",
uptime: process.uptime() + " seconds",
};
logger.info(`EXIT - ${request.method} ${request.url} - ${200}`);

return response.status(200).json(data);
} catch (err) {
logger.error(`ERROR - ${request.method} ${request.url} - ${err.message}`);
response.status(500).json({ message: "Server Error" });
}
};
2 changes: 2 additions & 0 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BackendController } from "./controllers/BackendController/BackendController";
import lapRouter from "./routes/lap.route";

import axios from "axios";
import axiosRetry from "axios-retry";
Expand Down Expand Up @@ -38,6 +39,7 @@ app.use((req, res, next) => {

app.use("/", healthRouter);
app.use("/", playbackRouter);
app.use("/", lapRouter);

export const logger = createLightweightApplicationLogger("index.ts");
axiosRetry(axios, {
Expand Down
9 changes: 9 additions & 0 deletions packages/server/src/routes/lap.route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from "express";

import * as controllers from "@/controllers/routeControllers/lap.controller";

const lapRouter = express.Router();

lapRouter.get("/lap", controllers.getLapData);

export default lapRouter;

0 comments on commit 3908dc1

Please sign in to comment.