Skip to content

Commit e9b2b85

Browse files
committed
try differing filtering
1 parent f0e4156 commit e9b2b85

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

services/registration/src/routes/statistics.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,29 @@ statisticsRouter.route("/").get(
5252
0
5353
);
5454

55-
const matchStage: any = {
55+
const baseMatch = {
5656
hexathon: new mongoose.Types.ObjectId(hexathon as string),
5757
};
5858

59+
const branchFilter: Record<string, any> = {};
5960
if (branchId) {
60-
matchStage.applicationBranch = new mongoose.Types.ObjectId(branchId);
61+
branchFilter.applicationBranch = new mongoose.Types.ObjectId(branchId);
6162
}
6263

63-
console.log("Running aggregation with matchStage:", matchStage);
64-
65-
const found = await ApplicationModel.find(matchStage).limit(3);
66-
console.log("Matched applications:", found.length);
64+
console.log("branchId", branchId);
65+
console.log("branchFilter", branchFilter);
6766

6867
const aggregatedApplications = await ApplicationModel.aggregate([
6968
{
70-
$match: matchStage,
69+
$match: baseMatch,
7170
},
7271
{
7372
$facet: {
7473
// users grouped by application status with frequency
7574
users: [
75+
{
76+
$match: branchFilter,
77+
},
7678
{
7779
$group: {
7880
_id: "$status",
@@ -84,6 +86,7 @@ statisticsRouter.route("/").get(
8486
genderData: [
8587
{
8688
$match: {
89+
...branchFilter,
8790
"status": { $ne: StatusType.DRAFT },
8891
"applicationData.gender": { $ne: null },
8992
},
@@ -99,6 +102,7 @@ statisticsRouter.route("/").get(
99102
schoolYearData: [
100103
{
101104
$match: {
105+
...branchFilter,
102106
"status": { $ne: StatusType.DRAFT },
103107
"applicationData.schoolYear": { $ne: null },
104108
},
@@ -114,6 +118,7 @@ statisticsRouter.route("/").get(
114118
majorData: [
115119
{
116120
$match: {
121+
...branchFilter,
117122
"status": { $ne: StatusType.DRAFT },
118123
"applicationData.major": { $ne: null },
119124
},
@@ -129,6 +134,7 @@ statisticsRouter.route("/").get(
129134
schoolData: [
130135
{
131136
$match: {
137+
...branchFilter,
132138
"status": { $ne: StatusType.DRAFT },
133139
"applicationData.school": { $ne: null },
134140
},
@@ -144,6 +150,7 @@ statisticsRouter.route("/").get(
144150
marketingData: [
145151
{
146152
$match: {
153+
...branchFilter,
147154
"status": { $ne: StatusType.DRAFT },
148155
"applicationData.marketing": { $ne: null },
149156
},
@@ -159,6 +166,7 @@ statisticsRouter.route("/").get(
159166
shirtSizeData: [
160167
{
161168
$match: {
169+
...branchFilter,
162170
"status": { $ne: StatusType.DRAFT },
163171
"applicationData.shirtSize": { $ne: null },
164172
},
@@ -174,6 +182,7 @@ statisticsRouter.route("/").get(
174182
dietaryRestrictionsData: [
175183
{
176184
$match: {
185+
...branchFilter,
177186
"status": { $ne: StatusType.DRAFT },
178187
"applicationData.dietaryRestrictions": { $ne: null },
179188
},
@@ -192,6 +201,7 @@ statisticsRouter.route("/").get(
192201
trackPreferenceData: [
193202
{
194203
$match: {
204+
...branchFilter,
195205
"status": { $ne: StatusType.DRAFT },
196206
"applicationData.customData.track": { $ne: null },
197207
},

0 commit comments

Comments
 (0)