This repository was archived by the owner on Oct 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathuser_list.ts
More file actions
122 lines (117 loc) · 3.68 KB
/
user_list.ts
File metadata and controls
122 lines (117 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import Application from "../models/Application";
import { Request, Response, application } from "express";
import { getGenericList } from "./common";
import { groupBy } from "lodash";
import { STATUS } from "../constants";
import { prepopulateMeetInfo } from "./meet_info";
export function getUserList(req: Request, res: Response) {
return getGenericList(req, res, Application);
}
export async function getMeetList(req: Request, res: Response) {
const results = await Application.find(
{
$and: [
{ status: STATUS.ADMISSION_CONFIRMED },
{ "forms.meet_info": { $exists: true } },
{ "forms.meet_info.showProfile": true },
],
},
{
"user.id": 1,
"forms.meet_info": 1,
"forms.application_info.first_name": 1,
"forms.application_info.last_name": 1,
"forms.team_info.teamList": 1,
}
);
let finalResults = results.map((result) => {
let obj = result.toObject();
prepopulateMeetInfo(obj);
return obj;
});
res.status(200).json({
results: finalResults,
count: results.length,
});
}
const facetStatsRequest = async () => {
const result = await Application.aggregate([
{
$facet: {
gender: [{ $sortByCount: "$forms.application_info.gender" }],
race: [
{
// "More than one" if multiple races are selected.
$sortByCount: {
$cond: {
if: {
$lte: [
{
$size: { $ifNull: ["$forms.application_info.race", []] },
},
1,
],
},
then: "$forms.application_info.race",
else: ["More than one"],
},
},
},
{ $unwind: "$_id" },
],
hackathon_experience: [
{ $sortByCount: "$forms.application_info.hackathon_experience" },
],
skill_level: [{ $sortByCount: "$forms.application_info.skill_level" }],
university: [{ $sortByCount: "$forms.application_info.university" }],
location: [{ $sortByCount: "$location" }],
type: [{ $sortByCount: "$type" }],
status: [{ $sortByCount: "$status" }],
graduation_year: [{ $sortByCount: "$forms.application_info.graduation_year" }],
},
},
]);
return result[0];
};
const timelineStatsRequest = async () => {
const applications = (await Application.find({}, { type: 1, status: 1, _id: 1 }).lean())
.map((application) => ({
...application,
date_created: application._id.getTimestamp(),
}))
.sort((a, b) => a.date_created - b.date_created);
let groupedByDay = groupBy(applications, (e) => e.date_created.toDateString());
let counter: { [x: string]: any } = {
type: { is: 0, oos: 0, stanford: 0 },
status: { submitted: 0, incomplete: 0 },
};
let results = [];
let i = 0;
for (let day in groupedByDay) {
for (let application of groupedByDay[day]) {
counter.type[application.type] = counter.type[application.type] + 1;
counter.status[application.status] = counter.status[application.status] + 1;
i++;
}
results.push({
num_is: counter.type.is,
num_oos: counter.type.oos,
num_stanford: counter.type.stanford,
num_incomplete: counter.status.incomplete,
num_submitted: counter.status.submitted,
date: new Date(day),
num_total: i,
});
}
return results;
};
export async function getUserStats(req: Request, res: Response) {
const [facetStatsResponse, timelineStatsResponse] = await Promise.all([
facetStatsRequest(),
timelineStatsRequest(),
]);
res.json({
...facetStatsResponse,
timeline: timelineStatsResponse,
});
}