Skip to content

Commit a1be731

Browse files
committed
allow filtering stats by status
1 parent 11b2455 commit a1be731

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

services/registration/src/routes/statistics.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ statisticsRouter.route("/").get(
2727
const { hexathon } = req.query;
2828
let applicationBranchId = req.query.applicationBranch as string | undefined;
2929
let confirmationBranchId = req.query.confirmationBranch as string | undefined;
30+
const appStatus = req.query.status as StatusType | undefined;
3031

3132
if (applicationBranchId === "") {
3233
applicationBranchId = undefined;
@@ -73,6 +74,11 @@ statisticsRouter.route("/").get(
7374
branchFilter.confirmationBranch = new mongoose.Types.ObjectId(confirmationBranchId);
7475
}
7576

77+
const statusFilter: Record<string, any> = {};
78+
if (appStatus) {
79+
statusFilter.status = appStatus;
80+
}
81+
7682
const aggregatedApplications = await ApplicationModel.aggregate([
7783
{
7884
$match: baseMatch,
@@ -96,7 +102,7 @@ statisticsRouter.route("/").get(
96102
{
97103
$match: {
98104
...branchFilter,
99-
"status": { $ne: StatusType.DRAFT },
105+
...statusFilter,
100106
"applicationData.gender": { $ne: null },
101107
},
102108
},
@@ -112,7 +118,7 @@ statisticsRouter.route("/").get(
112118
{
113119
$match: {
114120
...branchFilter,
115-
"status": { $ne: StatusType.DRAFT },
121+
...statusFilter,
116122
"applicationData.schoolYear": { $ne: null },
117123
},
118124
},
@@ -128,7 +134,7 @@ statisticsRouter.route("/").get(
128134
{
129135
$match: {
130136
...branchFilter,
131-
"status": { $ne: StatusType.DRAFT },
137+
...statusFilter,
132138
"applicationData.major": { $ne: null },
133139
},
134140
},
@@ -144,7 +150,7 @@ statisticsRouter.route("/").get(
144150
{
145151
$match: {
146152
...branchFilter,
147-
"status": { $ne: StatusType.DRAFT },
153+
...statusFilter,
148154
"applicationData.school": { $ne: null },
149155
},
150156
},
@@ -160,7 +166,7 @@ statisticsRouter.route("/").get(
160166
{
161167
$match: {
162168
...branchFilter,
163-
"status": { $ne: StatusType.DRAFT },
169+
...statusFilter,
164170
"applicationData.marketing": { $ne: null },
165171
},
166172
},
@@ -176,7 +182,7 @@ statisticsRouter.route("/").get(
176182
{
177183
$match: {
178184
...branchFilter,
179-
"status": { $ne: StatusType.DRAFT },
185+
...statusFilter,
180186
"applicationData.shirtSize": { $ne: null },
181187
},
182188
},
@@ -192,7 +198,7 @@ statisticsRouter.route("/").get(
192198
{
193199
$match: {
194200
...branchFilter,
195-
"status": { $ne: StatusType.DRAFT },
201+
...statusFilter,
196202
"applicationData.dietaryRestrictions": { $ne: null },
197203
},
198204
},
@@ -211,7 +217,7 @@ statisticsRouter.route("/").get(
211217
{
212218
$match: {
213219
...branchFilter,
214-
"status": { $ne: StatusType.DRAFT },
220+
...statusFilter,
215221
"applicationData.customData.track": { $ne: null },
216222
},
217223
},

0 commit comments

Comments
 (0)