Skip to content

Commit

Permalink
Add eventSignup endpoint and new getAllReservations EventService meth…
Browse files Browse the repository at this point in the history
…od. (#771)

* Add eventSignup endpoint and new getAllReservations EventService method.

Created new eventSignup endpoint and their controller.

Takes in a EventSignupBody and returns an EventSignupResponse.

Created EventService `getAllReservations` method and test.

* Minor updates to eventSignup endpoint and added tests

* Removes requirement for JWT in the endpoint.

* Checks if `max_occupancy` is undefined and **only** compares occupancy if `max_occupancy` isn't undefined.

* Use .trim to compare emails and workaround for checking max_occupancy

* Revert check for fetchedEvent.max_occupancy
  • Loading branch information
jeffplays2005 authored Sep 2, 2024
1 parent 22a93cd commit 346a959
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 6 deletions.
46 changes: 46 additions & 0 deletions client/src/models/__generated__/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions server/src/data-layer/services/EventService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ describe("EventService integration tests", () => {

await eventService.deleteEvent(newEvent.id)

const fetchedReservation1 = await eventService.getReservation(
const fetchedReservation1 = await eventService.getReservationById(
newEvent.id,
newReservation1.id
)
expect(fetchedReservation1).toBe(undefined)
const fetchedReservation2 = await eventService.getReservation(
const fetchedReservation2 = await eventService.getReservationById(
newEvent.id,
newReservation2.id
)
Expand All @@ -134,12 +134,12 @@ describe("EventService integration tests", () => {
)

await eventService.deleteEvent(newEvent.id)
const fetchedReservation3 = await eventService.getReservation(
const fetchedReservation3 = await eventService.getReservationById(
newEvent2.id,
newReservation3.id
)
expect(fetchedReservation3).toEqual(reservation1)
const fetchedReservation4 = await eventService.getReservation(
const fetchedReservation4 = await eventService.getReservationById(
newEvent2.id,
newReservation4.id
)
Expand Down Expand Up @@ -171,13 +171,23 @@ describe("EventService integration tests", () => {
newEvent.id,
reservation1
)
const fetchedReservation = await eventService.getReservation(
const fetchedReservation = await eventService.getReservationById(
newEvent.id,
reservation.id
)
expect(fetchedReservation).toEqual(reservation1)
})

it("Should get all event reservations", async () => {
const newEvent = await eventService.createEvent(event1)
await eventService.addReservation(newEvent.id, reservation1)
await eventService.addReservation(newEvent.id, reservation2)
const reservations = await eventService.getAllReservations(newEvent.id)
expect(reservations.length).toBe(2)
expect(reservations).toContainEqual(reservation1)
expect(reservations).toContainEqual(reservation2)
})

it("Should be able to update an event reservation", async () => {
const newEvent = await eventService.createEvent(event1)

Expand Down
12 changes: 11 additions & 1 deletion server/src/data-layer/services/EventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,24 @@ class EventService {
* @param reservationId the ID of the reservation document
* @returns the reservation document
*/
public async getReservation(eventId: string, reservationId: string) {
public async getReservationById(eventId: string, reservationId: string) {
const result = await FirestoreSubcollections.reservations(eventId)
.doc(reservationId)
.get()

return result.data()
}

/**
* Gets all reservations for an event.
* @param eventId the ID of the event document
* @returns an array of all the event reservation documents
*/
public async getAllReservations(eventId: string) {
const result = await FirestoreSubcollections.reservations(eventId).get()
return result.docs.map((doc) => doc.data())
}

/**
* Updates an existing reservation document by ID with new EventReservation data.
*
Expand Down
62 changes: 62 additions & 0 deletions server/src/middleware/__generated__/routes.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions server/src/middleware/__generated__/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 346a959

Please sign in to comment.