Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions docs/src/swagger-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Interaction"
"$ref": "#/definitions/Event"
}
}
},
Expand All @@ -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"],
Expand Down Expand Up @@ -1865,7 +1865,7 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Interaction"
"$ref": "#/definitions/Event"
}
}
},
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -4543,6 +4575,9 @@
"items": {
"type": "string"
}
},
"checkIns": {
"type": "number"
}
},
"xml": {
Expand Down
6 changes: 6 additions & 0 deletions services/hexathons/src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Event extends mongoose.Document {
endDate: Date;
location: AutoPopulatedDoc<Location>[];
tags: AutoPopulatedDoc<Tag>[];
checkIns: number;
}

const eventSchema = new Schema<Event>({
Expand Down Expand Up @@ -82,6 +83,11 @@ const eventSchema = new Schema<Event>({
],
default: [],
},
checkIns: {
type: Number,
required: false,
default: 0,
},
});

eventSchema.plugin(mongooseAutopopulate);
Expand Down
20 changes: 20 additions & 0 deletions services/hexathons/src/routes/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
})
);