Skip to content

Commit f5e93c8

Browse files
committed
fix broken error
1 parent ed2d810 commit f5e93c8

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

services/registration/src/routes/statistics.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ statisticsRouter.route("/").get(
2525
checkAbility("aggregate", "Application"),
2626
asyncHandler(async (req, res) => {
2727
const { hexathon } = req.query;
28+
let branchId = req.query.branch as string | undefined;
29+
30+
if (branchId === "") {
31+
branchId = undefined; // treat as undefined
32+
}
2833

2934
const branches = await BranchModel.find({
3035
hexathon: new mongoose.Types.ObjectId(hexathon as string),
@@ -47,11 +52,17 @@ statisticsRouter.route("/").get(
4752
0
4853
);
4954

55+
const matchStage: any = {
56+
hexathon: new mongoose.Types.ObjectId(hexathon as string),
57+
};
58+
59+
if (branchId) {
60+
matchStage.applicationBranch = new mongoose.Types.ObjectId(branchId);
61+
}
62+
5063
const aggregatedApplications = await ApplicationModel.aggregate([
5164
{
52-
$match: {
53-
hexathon: new mongoose.Types.ObjectId(hexathon as string),
54-
},
65+
$match: matchStage,
5566
},
5667
{
5768
$facet: {
@@ -331,6 +342,7 @@ statisticsRouter.route("/").get(
331342

332343
for (const interaction of eventInteractions) {
333344
if (!interaction.event) {
345+
// eslint-disable-next-line no-continue
334346
continue;
335347
}
336348
const event = interaction.event;

0 commit comments

Comments
 (0)