Skip to content

Commit

Permalink
Fixed edit event endpoint to properly parse timestamps (#808)
Browse files Browse the repository at this point in the history
* Fixed edit event endpoint to properly parse timestamps

* Added parsing in controller for timestamps

* Modified test case to try editing timestamp

* Destructure request body

* Also added error logging in case of server errors
  • Loading branch information
jeffplays2005 authored Oct 18, 2024
1 parent 1a2381d commit 2d249a4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
10 changes: 9 additions & 1 deletion server/src/middleware/tests/AdminController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event>)
.send({
title: "Cool event!",
location: "UoA",
physical_start_date: newDate
} as Partial<Event>)
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)
})
})
})
35 changes: 34 additions & 1 deletion server/src/service-layer/controllers/AdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2d249a4

Please sign in to comment.