diff --git a/docs/src/swagger-output.json b/docs/src/swagger-output.json index 9289332..1645340 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"], @@ -4543,6 +4575,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 f5aabb5..797c5ac 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 60d8f78..7ff57b9 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); @@ -114,3 +115,22 @@ eventRoutes.route("/:id").delete( return res.sendStatus(204); }) ); + +eventRoutes.route("/add-check-in/:id").patch( + checkAbility("update", "Event"), + asyncHandler(async (req, res) => { + const currentEvent = await EventModel.findById(req.params.id); + + const event = await EventModel.findByIdAndUpdate( + req.params.id, + { + $set: { + checkIns: currentEvent?.checkIns ? currentEvent.checkIns + 1 : 1, + }, + }, + { new: true } + ); + + res.send(event); + }) +);