diff --git a/server/src/middleware/tests/AdminController.test.ts b/server/src/middleware/tests/AdminController.test.ts index 1155408b..d481d6af 100644 --- a/server/src/middleware/tests/AdminController.test.ts +++ b/server/src/middleware/tests/AdminController.test.ts @@ -832,14 +832,22 @@ describe("AdminController endpoint tests", () => { }) it("should let admins edit an event", async () => { const newEvent = await eventService.createEvent(event1) + const newDate = dateToFirestoreTimeStamp(new Date()) const res = await request .patch("/admin/events/" + newEvent.id) .set("Authorization", `Bearer ${adminToken}`) - .send({ title: "Cool event!", location: "UoA" } as Partial) + .send({ + title: "Cool event!", + location: "UoA", + physical_start_date: newDate + } as Partial) expect(res.status).toEqual(200) const fetchedEvent = await eventService.getEventById(newEvent.id) expect(fetchedEvent.title).toEqual("Cool event!") expect(fetchedEvent.location).toEqual("UoA") + expect( + removeUnderscoresFromTimestamp(fetchedEvent.physical_start_date) + ).toEqual(newDate) }) }) }) diff --git a/server/src/service-layer/controllers/AdminController.ts b/server/src/service-layer/controllers/AdminController.ts index 69a234d9..bcd4055d 100644 --- a/server/src/service-layer/controllers/AdminController.ts +++ b/server/src/service-layer/controllers/AdminController.ts @@ -749,8 +749,41 @@ export class AdminController extends Controller { this.setStatus(404) } try { - eventService.updateEvent(id, requestBody) + const { + sign_up_start_date, + sign_up_end_date, + physical_start_date, + physical_end_date + } = requestBody + eventService.updateEvent(id, { + ...requestBody, + ...(sign_up_start_date && { + sign_up_start_date: new Timestamp( + sign_up_start_date.seconds, + sign_up_start_date.nanoseconds + ) + }), + ...(sign_up_end_date && { + sign_up_end_date: new Timestamp( + sign_up_end_date.seconds, + sign_up_end_date.nanoseconds + ) + }), + ...(physical_start_date && { + physical_start_date: new Timestamp( + physical_start_date.seconds, + physical_start_date.nanoseconds + ) + }), + ...(physical_end_date && { + physical_end_date: new Timestamp( + physical_end_date.seconds, + physical_end_date.nanoseconds + ) + }) + }) } catch (e) { + console.error(e) this.setStatus(500) } this.setStatus(200)