Skip to content

Commit

Permalink
added counts to /check-in endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pm3512 committed Jan 27, 2024
1 parent 401f6e7 commit 1faa856
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/controllers/CheckInController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,25 @@ export const getAllCheckInItems = async (
): Promise<void> => {
try {
const tartanhacks = await getTartanHacks();
const result = await CheckinItem.find({ event: tartanhacks._id }).sort({
startTime: 1,
});

const result = await CheckinItem.aggregate([
{ $match: { event: tartanhacks._id } },
{ $sort: { startTime: 1 } },
{
$lookup: {
from: "checkins",
localField: "_id",
foreignField: "item",
as: "checkins",
},
},
{
$addFields: {
// number of participants that checked in
checkinCount: { $size: "$checkins" },
},
},
{ $unset: "checkins" },
]);
res.status(200).json(result);
} catch (err) {
if (err.name === "CastError" || err.name === "ValidationError") {
Expand Down

0 comments on commit 1faa856

Please sign in to comment.