From 48c3a2c2afd23c4ba8a03ab95ae956f8bfb62d39 Mon Sep 17 00:00:00 2001 From: jeffplays2005 Date: Sat, 2 Nov 2024 14:29:40 +1300 Subject: [PATCH] Regenerate schema and update endpoint in controller and tests --- client/src/models/__generated__/schema.d.ts | 44 +++++++++---------- server/src/middleware/__generated__/routes.ts | 2 +- .../src/middleware/__generated__/swagger.json | 4 +- .../middleware/tests/AdminController.test.ts | 6 +-- .../controllers/AdminController.ts | 2 +- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/client/src/models/__generated__/schema.d.ts b/client/src/models/__generated__/schema.d.ts index 2b5d2552..27721c4a 100644 --- a/client/src/models/__generated__/schema.d.ts +++ b/client/src/models/__generated__/schema.d.ts @@ -59,9 +59,6 @@ export interface paths { */ get: operations["GetAllEvents"]; }; - "/events/{id}": { - get: operations["GetEventById"]; - }; "/bookings": { /** @description Fetches all bookings for a user based on their UID. */ get: operations["GetAllBookings"]; @@ -155,6 +152,7 @@ export interface paths { post: operations["CreateNewEvent"]; }; "/admin/events/{id}": { + get: operations["GetEventById"]; /** @description Endpoint for admints to edit an event. */ patch: operations["EditEvent"]; }; @@ -365,11 +363,6 @@ export interface components { nextCursor?: string; data?: components["schemas"]["DocumentDataWithUid_Event_"][]; }; - GetEventResponse: { - error?: string; - message?: string; - data?: components["schemas"]["Event"]; - }; AllUserBookingSlotsResponse: { error?: string; message?: string; @@ -744,6 +737,11 @@ export interface components { */ max_occupancy?: number; }; + GetEventResponse: { + error?: string; + message?: string; + data?: components["schemas"]["Event"]; + }; }; responses: { }; @@ -956,21 +954,6 @@ export interface operations { }; }; }; - GetEventById: { - parameters: { - path: { - id: string; - }; - }; - responses: { - /** @description Successfully fetched the event */ - 200: { - content: { - "application/json": components["schemas"]["GetEventResponse"]; - }; - }; - }; - }; /** @description Fetches all bookings for a user based on their UID. */ GetAllBookings: { responses: { @@ -1259,6 +1242,21 @@ export interface operations { }; }; }; + GetEventById: { + parameters: { + path: { + id: string; + }; + }; + responses: { + /** @description Successfully fetched the event */ + 200: { + content: { + "application/json": components["schemas"]["GetEventResponse"]; + }; + }; + }; + }; /** @description Endpoint for admints to edit an event. */ EditEvent: { parameters: { diff --git a/server/src/middleware/__generated__/routes.ts b/server/src/middleware/__generated__/routes.ts index 05153a92..6fe48e9a 100644 --- a/server/src/middleware/__generated__/routes.ts +++ b/server/src/middleware/__generated__/routes.ts @@ -1466,7 +1466,7 @@ export function RegisterRoutes(app: Router) { } }); // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa - app.get('/admin/:id', + app.get('/admin/events/:id', authenticateMiddleware([{"jwt":["admin"]}]), ...(fetchMiddlewares(AdminController)), ...(fetchMiddlewares(AdminController.prototype.getEventById)), diff --git a/server/src/middleware/__generated__/swagger.json b/server/src/middleware/__generated__/swagger.json index 2fb8ea5b..2e75f3d5 100644 --- a/server/src/middleware/__generated__/swagger.json +++ b/server/src/middleware/__generated__/swagger.json @@ -2467,9 +2467,7 @@ } } } - } - }, - "/admin/{id}": { + }, "get": { "operationId": "GetEventById", "responses": { diff --git a/server/src/middleware/tests/AdminController.test.ts b/server/src/middleware/tests/AdminController.test.ts index 2fbd274f..e6ac84b7 100644 --- a/server/src/middleware/tests/AdminController.test.ts +++ b/server/src/middleware/tests/AdminController.test.ts @@ -850,7 +850,7 @@ describe("AdminController endpoint tests", () => { ).toEqual(newDate) }) }) - describe("GET /events/:id", () => { + describe("GET /admin/events/:id", () => { const event1: Event = { title: "UASC New event", physical_start_date: dateToFirestoreTimeStamp(new Date()), @@ -862,7 +862,7 @@ describe("AdminController endpoint tests", () => { it("should return the event details for a valid event ID", async () => { const { id: id1 } = await eventService.createEvent(event1) - const res = await request.get(`/events/${id1}`).send() + const res = await request.get(`/admin/events/${id1}`).send() expect(res.status).toEqual(200) expect(res.body.data).toBeDefined() expect(res.body.data.title).toEqual("UASC New event") @@ -870,7 +870,7 @@ describe("AdminController endpoint tests", () => { }) it("should return 404 if the event does not exist", async () => { - const res = await request.get("/events/random-event").send() + const res = await request.get("/admin/events/random-event").send() expect(res.status).toEqual(404) expect(res.body.error).toEqual("Event not found.") }) diff --git a/server/src/service-layer/controllers/AdminController.ts b/server/src/service-layer/controllers/AdminController.ts index 941d308e..3a37d001 100644 --- a/server/src/service-layer/controllers/AdminController.ts +++ b/server/src/service-layer/controllers/AdminController.ts @@ -792,8 +792,8 @@ export class AdminController extends Controller { this.setStatus(200) } - @Get("{id}") @SuccessResponse("200", "Successfully fetched the event") + @Get("events/{id}") public async getEventById(@Path() id: string): Promise { try { const eventService = new EventService()