From 13b98f891c50a70acccb0149786cad237665ee30 Mon Sep 17 00:00:00 2001 From: Amy <45153739+amtang325@users.noreply.github.com> Date: Mon, 29 Jul 2024 19:37:54 -0400 Subject: [PATCH 1/4] updated documentation --- docs/src/swagger-output.json | 3 +++ services/hexathons/src/models/event.ts | 6 ++++++ services/hexathons/src/routes/event.ts | 1 + 3 files changed, 10 insertions(+) diff --git a/docs/src/swagger-output.json b/docs/src/swagger-output.json index 9289332f..634a1c5b 100644 --- a/docs/src/swagger-output.json +++ b/docs/src/swagger-output.json @@ -4543,6 +4543,9 @@ "items": { "type": "string" } + }, + "checkIns": { + "type": "number" } }, "xml": { diff --git a/services/hexathons/src/models/event.ts b/services/hexathons/src/models/event.ts index f5aabb57..797c5acb 100644 --- a/services/hexathons/src/models/event.ts +++ b/services/hexathons/src/models/event.ts @@ -27,6 +27,7 @@ export interface Event extends mongoose.Document { endDate: Date; location: AutoPopulatedDoc[]; tags: AutoPopulatedDoc[]; + checkIns: number; } const eventSchema = new Schema({ @@ -82,6 +83,11 @@ const eventSchema = new Schema({ ], default: [], }, + checkIns: { + type: Number, + required: false, + default: 0, + }, }); eventSchema.plugin(mongooseAutopopulate); diff --git a/services/hexathons/src/routes/event.ts b/services/hexathons/src/routes/event.ts index 60d8f789..1bc68f80 100644 --- a/services/hexathons/src/routes/event.ts +++ b/services/hexathons/src/routes/event.ts @@ -65,6 +65,7 @@ eventRoutes.route("/").post( endDate: req.body.endDate, location: req.body.location, tags: req.body.tags, + checkIns: req.body.checkIns || 0, }); return res.send(event); From d9172ef80470f8bf119bcf0b2b06572ba91423ca Mon Sep 17 00:00:00 2001 From: Amy <45153739+amtang325@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:49:13 -0400 Subject: [PATCH 2/4] added new route --- services/hexathons/src/routes/event.ts | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/services/hexathons/src/routes/event.ts b/services/hexathons/src/routes/event.ts index 1bc68f80..6a3badd8 100644 --- a/services/hexathons/src/routes/event.ts +++ b/services/hexathons/src/routes/event.ts @@ -108,6 +108,35 @@ eventRoutes.route("/:id").patch( }) ); +eventRoutes.route("/add-check-in/:id").patch( + checkAbility("update", "Event"), + asyncHandler(async (req, res) => { + const currentEvent = await EventModel.findById(req.params.id); + const existingEvent = await EventModel.findOne({ + hexathon: currentEvent?.hexathon, + name: req.body.name, + }); + + if (existingEvent && existingEvent.id !== req.params.id) { + throw new BadRequestError( + `Event with name ${req.body.name} already exists for this hexathon` + ); + } + + const event = await EventModel.findByIdAndUpdate( + req.params.id, + { + $set: { + checkIns: currentEvent?.checkIns ? currentEvent.checkIns + 1 : 1, + }, + }, + { new: true } + ); + + res.send(event); + }) +); + eventRoutes.route("/:id").delete( checkAbility("delete", "Event"), asyncHandler(async (req, res) => { From 9c2ef60459ddc1713a275f86423dd58f432fa04c Mon Sep 17 00:00:00 2001 From: Amy <45153739+amtang325@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:56:14 -0400 Subject: [PATCH 3/4] updated documentation --- docs/src/swagger-output.json | 38 ++++++++++++++++++++++++-- services/hexathons/src/routes/event.ts | 16 +++++------ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/docs/src/swagger-output.json b/docs/src/swagger-output.json index 634a1c5b..16453408 100644 --- a/docs/src/swagger-output.json +++ b/docs/src/swagger-output.json @@ -1783,7 +1783,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/Interaction" + "$ref": "#/definitions/Event" } } }, @@ -1796,7 +1796,7 @@ "/events/{id}": { "patch": { "tags": ["hexathons"], - "summary": "Update an existing interaction by id.", + "summary": "Update an existing event by id.", "description": "", "consumes": ["application/json"], "produces": ["application/json"], @@ -1865,7 +1865,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/Interaction" + "$ref": "#/definitions/Event" } } }, @@ -1898,6 +1898,38 @@ } } }, + "/events/add-check-in/{id}": { + "patch": { + "tags": ["hexathons"], + "summary": "Increments check-in counter for an event by id.", + "description": "", + "consumes": ["application/json"], + "produces": ["application/json"], + "parameters": [ + { + "name": "id", + "in": "path", + "description": "Event id that needs to be considered for filter.", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Event" + } + } + }, + "400": { + "description": "Invalid Status" + } + } + } + }, "/swag-items": { "get": { "tags": ["hexathons"], diff --git a/services/hexathons/src/routes/event.ts b/services/hexathons/src/routes/event.ts index 6a3badd8..64b20a77 100644 --- a/services/hexathons/src/routes/event.ts +++ b/services/hexathons/src/routes/event.ts @@ -108,6 +108,14 @@ eventRoutes.route("/:id").patch( }) ); +eventRoutes.route("/:id").delete( + checkAbility("delete", "Event"), + asyncHandler(async (req, res) => { + await EventModel.findByIdAndDelete(req.params.id); + return res.sendStatus(204); + }) +); + eventRoutes.route("/add-check-in/:id").patch( checkAbility("update", "Event"), asyncHandler(async (req, res) => { @@ -136,11 +144,3 @@ eventRoutes.route("/add-check-in/:id").patch( res.send(event); }) ); - -eventRoutes.route("/:id").delete( - checkAbility("delete", "Event"), - asyncHandler(async (req, res) => { - await EventModel.findByIdAndDelete(req.params.id); - return res.sendStatus(204); - }) -); From 458816b13cb97c3653121ef2841a708a3aff6920 Mon Sep 17 00:00:00 2001 From: Amy <45153739+amtang325@users.noreply.github.com> Date: Mon, 29 Jul 2024 21:45:38 -0400 Subject: [PATCH 4/4] removed name handling for route --- services/hexathons/src/routes/event.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/services/hexathons/src/routes/event.ts b/services/hexathons/src/routes/event.ts index 64b20a77..7ff57b90 100644 --- a/services/hexathons/src/routes/event.ts +++ b/services/hexathons/src/routes/event.ts @@ -120,16 +120,6 @@ eventRoutes.route("/add-check-in/:id").patch( checkAbility("update", "Event"), asyncHandler(async (req, res) => { const currentEvent = await EventModel.findById(req.params.id); - const existingEvent = await EventModel.findOne({ - hexathon: currentEvent?.hexathon, - name: req.body.name, - }); - - if (existingEvent && existingEvent.id !== req.params.id) { - throw new BadRequestError( - `Event with name ${req.body.name} already exists for this hexathon` - ); - } const event = await EventModel.findByIdAndUpdate( req.params.id,