From 51ba810711ce62a1d00634509374526f031ed898 Mon Sep 17 00:00:00 2001 From: Kan-A-Pesh Date: Tue, 29 Oct 2024 16:54:48 +0100 Subject: [PATCH] chore: add daily endpoint --- package.json | 1 + routes.ts | 3 +++ routes/daily.ts | 19 +++++++++++++++++++ tests/e2e/clubs.test.ts | 4 +--- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 routes/daily.ts diff --git a/package.json b/package.json index ee32bfc..9ce49d2 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "format": "prettier --write .", "lint": "eslint .", "clear": "rm -rf dist node_modules coverage logs/*.log", + "clear:logs": "rm -rf logs/*.log", "db:migrate": "drizzle-kit generate" }, "author": { diff --git a/routes.ts b/routes.ts index 3b10b0c..fdb1805 100644 --- a/routes.ts +++ b/routes.ts @@ -2,10 +2,13 @@ import { Router } from "express"; import clubsRouter from "./routes/clubs/router"; import adminRouter from "./routes/admin/router"; import Route_Index_Read from "./routes/index"; +import Route_Daily_Read from "./routes/daily"; const router = Router(); router.get("/", Route_Index_Read); +router.get("/daily", Route_Daily_Read); + router.use("/clubs", clubsRouter); router.use("/admin", adminRouter); diff --git a/routes/daily.ts b/routes/daily.ts new file mode 100644 index 0000000..4781b69 --- /dev/null +++ b/routes/daily.ts @@ -0,0 +1,19 @@ +import ClubController from "@/controllers/clubs"; +import Status from "@/models/status"; +import { NextFunction, Request, Response } from "express"; + +export default async function Route_Daily_Read(req: Request, res: Response, next: NextFunction) { + const club = await ClubController.getDailyClub(); + + if (!club) { + return Status.send(req, next, { + status: 404, + error: "errors.notFound" + }); + } + + return Status.send(req, next, { + status: 200, + data: club + }); +} diff --git a/tests/e2e/clubs.test.ts b/tests/e2e/clubs.test.ts index 8e76358..94fbd9c 100644 --- a/tests/e2e/clubs.test.ts +++ b/tests/e2e/clubs.test.ts @@ -185,9 +185,7 @@ describe("Test users", () => { }); test("should get daily club", async () => { - const res = await get(app, "/daily", undefined, undefined, { - "X-ADMIN-KEY": globals.env.ADMIN_TOKEN - }); + const res = await get(app, "/daily"); expect(res.body).toStrictEqual({ masterStatus: 200,