From c74157175f2e21c32d5b88d11d71e00b15fd4d92 Mon Sep 17 00:00:00 2001 From: jeffplays2005 Date: Mon, 16 Sep 2024 11:59:31 +1200 Subject: [PATCH] Add a signup timestamp to the EventReservation Type Updated tests as well --- client/src/models/__generated__/schema.d.ts | 7 +++++-- server/src/data-layer/models/firebase.ts | 4 ++++ .../data-layer/services/EventService.test.ts | 20 +++++++++++-------- server/src/middleware/__generated__/routes.ts | 19 +++++++++--------- .../src/middleware/__generated__/swagger.json | 10 +++++++--- .../middleware/tests/EventController.test.ts | 8 ++++++-- .../controllers/EventController.ts | 6 +++++- .../request-models/EventRequests.ts | 2 +- 8 files changed, 49 insertions(+), 27 deletions(-) diff --git a/client/src/models/__generated__/schema.d.ts b/client/src/models/__generated__/schema.d.ts index 2859e8499..87e45af48 100644 --- a/client/src/models/__generated__/schema.d.ts +++ b/client/src/models/__generated__/schema.d.ts @@ -305,7 +305,8 @@ export interface components { first_name: string; }; }; - EventReservation: { + /** @description From T, pick a set of properties whose keys are in the union K */ + "Pick_EventReservation.Exclude_keyofEventReservation.timestamp__": { /** @description The first name of the user who made this event reservation */ first_name: string; /** @description The last name of the user who made this event reservation */ @@ -318,9 +319,11 @@ export interface components { */ is_member: boolean; }; + /** @description Construct a type with the properties of T except for those in type K. */ + "Omit_EventReservation.timestamp_": components["schemas"]["Pick_EventReservation.Exclude_keyofEventReservation.timestamp__"]; EventSignupBody: { event_id: string; - reservation: components["schemas"]["EventReservation"]; + reservation: components["schemas"]["Omit_EventReservation.timestamp_"]; }; AllUserBookingSlotsResponse: { error?: string; diff --git a/server/src/data-layer/models/firebase.ts b/server/src/data-layer/models/firebase.ts index a5822667c..4e5282f4f 100644 --- a/server/src/data-layer/models/firebase.ts +++ b/server/src/data-layer/models/firebase.ts @@ -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 { diff --git a/server/src/data-layer/services/EventService.test.ts b/server/src/data-layer/services/EventService.test.ts index 7b8a9d972..abf0fde5a 100644 --- a/server/src/data-layer/services/EventService.test.ts +++ b/server/src/data-layer/services/EventService.test.ts @@ -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 = { @@ -39,13 +41,15 @@ const reservation1: EventReservation = { first_name: "John", last_name: "Appleseed", email: "test@gmail.com", - is_member: true + is_member: true, + timestamp: Timestamp.fromDate(startDate) } const reservation2: EventReservation = { first_name: "Jane", last_name: "Pearseed", email: "test2@gmail.com", - is_member: false + is_member: false, + timestamp: Timestamp.fromDate(startDate) } describe("EventService integration tests", () => { diff --git a/server/src/middleware/__generated__/routes.ts b/server/src/middleware/__generated__/routes.ts index 9c862ffc8..b94db6670 100644 --- a/server/src/middleware/__generated__/routes.ts +++ b/server/src/middleware/__generated__/routes.ts @@ -190,22 +190,21 @@ const models: TsoaRoute.Models = { "additionalProperties": false, }, // 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 - "EventReservation": { - "dataType": "refObject", - "properties": { - "first_name": {"dataType":"string","required":true}, - "last_name": {"dataType":"string","required":true}, - "email": {"dataType":"string","required":true}, - "is_member": {"dataType":"boolean","required":true}, - }, - "additionalProperties": false, + "Pick_EventReservation.Exclude_keyofEventReservation.timestamp__": { + "dataType": "refAlias", + "type": {"dataType":"nestedObjectLiteral","nestedProperties":{"first_name":{"dataType":"string","required":true},"last_name":{"dataType":"string","required":true},"email":{"dataType":"string","required":true},"is_member":{"dataType":"boolean","required":true}},"validators":{}}, + }, + // 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 + "Omit_EventReservation.timestamp_": { + "dataType": "refAlias", + "type": {"ref":"Pick_EventReservation.Exclude_keyofEventReservation.timestamp__","validators":{}}, }, // 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 "EventSignupBody": { "dataType": "refObject", "properties": { "event_id": {"dataType":"string","required":true}, - "reservation": {"ref":"EventReservation","required":true}, + "reservation": {"ref":"Omit_EventReservation.timestamp_","required":true}, }, "additionalProperties": false, }, diff --git a/server/src/middleware/__generated__/swagger.json b/server/src/middleware/__generated__/swagger.json index dc1908ec9..86463f986 100644 --- a/server/src/middleware/__generated__/swagger.json +++ b/server/src/middleware/__generated__/swagger.json @@ -426,7 +426,7 @@ "type": "object", "additionalProperties": false }, - "EventReservation": { + "Pick_EventReservation.Exclude_keyofEventReservation.timestamp__": { "properties": { "first_name": { "type": "string", @@ -453,7 +453,11 @@ "is_member" ], "type": "object", - "additionalProperties": false + "description": "From T, pick a set of properties whose keys are in the union K" + }, + "Omit_EventReservation.timestamp_": { + "$ref": "#/components/schemas/Pick_EventReservation.Exclude_keyofEventReservation.timestamp__", + "description": "Construct a type with the properties of T except for those in type K." }, "EventSignupBody": { "properties": { @@ -461,7 +465,7 @@ "type": "string" }, "reservation": { - "$ref": "#/components/schemas/EventReservation" + "$ref": "#/components/schemas/Omit_EventReservation.timestamp_" } }, "required": [ diff --git a/server/src/middleware/tests/EventController.test.ts b/server/src/middleware/tests/EventController.test.ts index 0954d0d0b..9eed2f1a8 100644 --- a/server/src/middleware/tests/EventController.test.ts +++ b/server/src/middleware/tests/EventController.test.ts @@ -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)) @@ -11,7 +12,7 @@ const event1: Event = { start_date: startDate, end_date: endDate } -const reservation1: EventReservation = { +const reservation1: Omit = { first_name: "John", last_name: "Doe", email: "test@email.com", @@ -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 diff --git a/server/src/service-layer/controllers/EventController.ts b/server/src/service-layer/controllers/EventController.ts index 81d3a2564..bf9710149 100644 --- a/server/src/service-layer/controllers/EventController.ts +++ b/server/src/service-layer/controllers/EventController.ts @@ -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 { @@ -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.", diff --git a/server/src/service-layer/request-models/EventRequests.ts b/server/src/service-layer/request-models/EventRequests.ts index 74ae6ebdc..d85eeff08 100644 --- a/server/src/service-layer/request-models/EventRequests.ts +++ b/server/src/service-layer/request-models/EventRequests.ts @@ -2,5 +2,5 @@ import { EventReservation } from "data-layer/models/firebase" export interface EventSignupBody { event_id: string - reservation: EventReservation + reservation: Omit }