Skip to content

Commit 1feb846

Browse files
committed
add hackathon param to application analytics route
1 parent e37646c commit 1feb846

5 files changed

Lines changed: 69 additions & 22 deletions

File tree

‎openapi.json‎

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/api-client/src/generated/analytics/analytics.ts‎

Lines changed: 22 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/api-client/src/generated/model/analyticsGetApplicationAnalyticsParams.ts‎

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/api-client/src/generated/model/index.ts‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/modules/analytics/analytics.controller.ts‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ export class AnalyticsController {
440440

441441
private async calculateApplicationMetrics(
442442
applications: any[],
443+
hackathonId?: string,
443444
): Promise<ApplicationMetrics> {
444445
const confirmedApplicants = applications.filter(
445446
(app) => app.applicationStatus === "confirmed",
@@ -458,7 +459,7 @@ export class AnalyticsController {
458459

459460
const confirmedAndScannedApplicants = await this.scanRepo
460461
.findAll()
461-
.byHackathon()
462+
.byHackathon(hackathonId)
462463
.joinRelated("event")
463464
.whereIn(
464465
"user_id",
@@ -490,23 +491,31 @@ export class AnalyticsController {
490491

491492
@Get("/applications")
492493
@Roles(Role.NONE)
494+
@ApiQuery({
495+
name: "hackathonId",
496+
required: false,
497+
type: String,
498+
description:
499+
"The hackathon ID to fetch application metrics for. Defaults to the active hackathon.",
500+
})
493501
@ApiDoc({
494502
summary: "Get application metrics for each event",
495503
auth: Role.TEAM,
496504
response: {
497505
ok: { type: AnalyticsApplicationsResponse },
498506
},
499507
})
500-
async getApplicationAnalytics() {
508+
async getApplicationAnalytics(@Query("hackathonId") hackathonId?: string) {
501509
// Matches every Penn State campus, not just Main Campus
502510
const PENN_STATE_PREFIX = "The Pennsylvania State University";
503511
const isPennState = (university?: string | null) =>
504512
university?.startsWith(PENN_STATE_PREFIX) ?? false;
505513

506-
// Get all registrations with user information for the active hackathon
514+
// Get all registrations with user information for the requested hackathon
515+
// (falls back to the active hackathon when no ID is provided)
507516
const applications = await this.registrationRepo
508517
.findAll()
509-
.byHackathon()
518+
.byHackathon(hackathonId)
510519
.withGraphFetched("user");
511520

512521
// Separate Penn State and Other students
@@ -517,10 +526,15 @@ export class AnalyticsController {
517526
(app) => !isPennState(app.user?.university),
518527
);
519528

520-
const pennStateMetrics =
521-
await this.calculateApplicationMetrics(pennStateApps);
529+
const pennStateMetrics = await this.calculateApplicationMetrics(
530+
pennStateApps,
531+
hackathonId,
532+
);
522533

523-
const otherMetrics = await this.calculateApplicationMetrics(otherApps);
534+
const otherMetrics = await this.calculateApplicationMetrics(
535+
otherApps,
536+
hackathonId,
537+
);
524538

525539
return {
526540
pennState: pennStateMetrics,

0 commit comments

Comments
 (0)