Skip to content

Commit

Permalink
Add a signup timestamp to the EventReservation Type (#784)
Browse files Browse the repository at this point in the history
Updated tests as well
  • Loading branch information
jeffplays2005 authored Sep 16, 2024
1 parent 0a1f8c1 commit 958a353
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 27 deletions.
7 changes: 5 additions & 2 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.

4 changes: 4 additions & 0 deletions server/src/data-layer/models/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export interface EventReservation {
* @example true
*/
is_member: boolean
/**
* This is the timestamp of when the reservation was made
*/
timestamp: Timestamp
}

export interface Event {
Expand Down
20 changes: 12 additions & 8 deletions server/src/data-layer/services/EventService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ import { Timestamp } from "firebase-admin/firestore"

const eventService = new EventService()

const startDate = dateToFirestoreTimeStamp(new Date(2024, 1, 1))
const endDate = dateToFirestoreTimeStamp(new Date(2024, 1, 2))
const startDate = new Date(2024, 1, 1)
const endDate = new Date(2024, 1, 2)
const startTimestamp = dateToFirestoreTimeStamp(startDate)
const endTimestamp = dateToFirestoreTimeStamp(endDate)

const event1: Event = {
title: "UASC new event",
description: "Grand opening of the website.",
location: "Virtual pizza event",
start_date: startDate,
end_date: endDate
start_date: startTimestamp,
end_date: endTimestamp
}
const event2: Event = {
title: "Snowboard racing",
description: "Race and see who's the fastest!",
location: "Snowsport club",
start_date: startDate,
end_date: endDate
start_date: startTimestamp,
end_date: endTimestamp
}
const now = new Date(Date.now())
const futureEvent: Event = {
Expand All @@ -39,13 +41,15 @@ const reservation1: EventReservation = {
first_name: "John",
last_name: "Appleseed",
email: "[email protected]",
is_member: true
is_member: true,
timestamp: Timestamp.fromDate(startDate)
}
const reservation2: EventReservation = {
first_name: "Jane",
last_name: "Pearseed",
email: "[email protected]",
is_member: false
is_member: false,
timestamp: Timestamp.fromDate(startDate)
}

describe("EventService integration tests", () => {
Expand Down
19 changes: 9 additions & 10 deletions server/src/middleware/__generated__/routes.ts

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

10 changes: 7 additions & 3 deletions server/src/middleware/__generated__/swagger.json

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

8 changes: 6 additions & 2 deletions server/src/middleware/tests/EventController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import EventService from "data-layer/services/EventService"
import { request } from "../routes.setup"
import { Event, EventReservation } from "../../data-layer/models/firebase"
import { dateToFirestoreTimeStamp } from "data-layer/adapters/DateUtils"
import { Timestamp } from "firebase-admin/firestore"

const startDate = dateToFirestoreTimeStamp(new Date(2024, 1, 1))
const endDate = dateToFirestoreTimeStamp(new Date(2024, 1, 2))
Expand All @@ -11,7 +12,7 @@ const event1: Event = {
start_date: startDate,
end_date: endDate
}
const reservation1: EventReservation = {
const reservation1: Omit<EventReservation, "timestamp"> = {
first_name: "John",
last_name: "Doe",
email: "[email protected]",
Expand Down Expand Up @@ -44,7 +45,10 @@ describe("EventController endpoint tests", () => {

it("should return 400 if already signed up to event", async () => {
const event = await eventService.createEvent(event1)
await eventService.addReservation(event.id, reservation1)
await eventService.addReservation(event.id, {
...reservation1,
timestamp: Timestamp.now()
})
const res = await request.post("/events/signup").send({
event_id: event.id,
reservation: reservation1
Expand Down
6 changes: 5 additions & 1 deletion server/src/service-layer/controllers/EventController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SuccessResponse
} from "tsoa"
import express from "express"
import { Timestamp } from "firebase-admin/firestore"

@Route("events")
export class EventController extends Controller {
Expand Down Expand Up @@ -52,7 +53,10 @@ export class EventController extends Controller {
}
// Sign up the user
try {
await eventService.addReservation(event_id, reservation)
await eventService.addReservation(event_id, {
...reservation,
timestamp: Timestamp.now()
})
this.setStatus(200)
return {
message: "Successfully signed up for event.",
Expand Down
2 changes: 1 addition & 1 deletion server/src/service-layer/request-models/EventRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { EventReservation } from "data-layer/models/firebase"

export interface EventSignupBody {
event_id: string
reservation: EventReservation
reservation: Omit<EventReservation, "timestamp">
}

0 comments on commit 958a353

Please sign in to comment.