Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/modules/analytics/analytics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ const RACE_CATEGORIES: { label: string; patterns: string[] }[] = [
{ label: "Asian", patterns: ["asian"] },
{ label: "Caucasian", patterns: ["caucasian", "white"] },
{ label: "Hispanic or Latinx", patterns: ["hispanic", "latinx"] },
{ label: "Black or African American", patterns: ["black or african american", "african american"] },
{ label: "Native American or Alaska Native", patterns: ["native american", "alaska native"] },
{ label: "Native Hawaiian or Other Pacific Islander", patterns: ["native hawaiian", "pacific islander"] },
{
label: "Black or African American",
patterns: ["black or african american", "african american"],
},
{
label: "Native American or Alaska Native",
patterns: ["native american", "alaska native"],
},
{
label: "Native Hawaiian or Other Pacific Islander",
patterns: ["native hawaiian", "pacific islander"],
},
{ label: "Prefer not to say", patterns: ["nodisclose", "prefer not to say"] },
{ label: "Multiracial", patterns: ["multiracial"] },
];
Expand Down Expand Up @@ -218,7 +227,10 @@ export class AnalyticsController {
const result = (await this.userRepo
.findAll()
.byHackathon()
.whereRaw(`(${whereClause})`, patterns.map((p) => `%${p}%`))
.whereRaw(
`(${whereClause})`,
patterns.map((p) => `%${p}%`),
)
.count("users.id", { as: "count" })
.first()) as any;
return { race: label, count: Number(result?.count ?? 0) };
Expand Down Expand Up @@ -454,9 +466,7 @@ export class AnalyticsController {
? confirmedAndScannedApplicants.length / confirmedApplicants.length
: 0,
confirmRate:
totalAccepted > 0
? confirmedApplicants.length / totalAccepted
: 0,
totalAccepted > 0 ? confirmedApplicants.length / totalAccepted : 0,
averageConfirmTime:
confirmedApplicants.length > 0
? confirmedApplicants.reduce(
Expand Down Expand Up @@ -497,9 +507,8 @@ export class AnalyticsController {
(app) => app.user.university !== PENN_STATE_UNIVERSITY,
);

const pennStateMetrics = await this.calculateApplicationMetrics(
pennStateApps,
);
const pennStateMetrics =
await this.calculateApplicationMetrics(pennStateApps);

const otherMetrics = await this.calculateApplicationMetrics(otherApps);

Expand Down
60 changes: 20 additions & 40 deletions src/modules/event/event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,15 @@ export class EventController {
)
data: CreateScanEntity,
) {
const event = await this.eventRepo.findOne(id).exec();
const user = await this.userRepo.findOne(userId).exec();
const [event, user, userRegistration] = await Promise.all([
this.eventRepo.findOne(id).exec(),
this.userRepo.findOne(userId).exec(),
this.registrationRepo
.findAll()
.byHackathon(data.hackathonId)
.where("userId", userId)
.first(),
]);

if (!event) {
throw new HttpException("event not found", HttpStatus.BAD_REQUEST);
Expand All @@ -468,13 +475,6 @@ export class EventController {
throw new HttpException("user not found", HttpStatus.BAD_REQUEST);
}

// check if user is registered for the current hackathon
const registration = await this.registrationRepo.findAll().exec();
const userRegistration = registration
.filter((r) => r.userId == userId)
.filter((r) => r.hackathonId == data.hackathonId)[0];
console.log("user registration", userRegistration);

if (!userRegistration) {
throw new HttpException(
"User is not registered for the current hackathon",
Expand All @@ -490,10 +490,11 @@ export class EventController {
}

if (event.type != EventType.checkIn) {
// Find check-in event
const checkInEvent = await (await this.eventRepo.findAll().exec())
.filter((e) => e.type == EventType.checkIn)
.filter((e) => e.hackathonId == data.hackathonId)[0];
const checkInEvent = await this.eventRepo
.findAll()
.byHackathon(data.hackathonId)
.where("type", EventType.checkIn)
.first();

if (!checkInEvent) {
throw new HttpException(
Expand All @@ -502,13 +503,12 @@ export class EventController {
);
}

const events = await this.scanRepo.findAll().exec();
const checkInScan = events.filter(
(e) =>
e.eventId == checkInEvent.id &&
e.userId == userId &&
e.hackathonId == data.hackathonId,
)[0];
const checkInScan = await this.scanRepo
.findAll()
.byHackathon(data.hackathonId)
.where("eventId", checkInEvent.id)
.where("userId", userId)
.first();

if (!checkInScan) {
throw new HttpException(
Expand Down Expand Up @@ -552,25 +552,5 @@ export class EventController {
} catch (e) {
console.error(`Cannot send token message to: ${userId}`, e);
}

// Send Gotify notification for check-in
try {
const totalScans = await this.scanRepo
.findAll()
.byHackathon(data.hackathonId)
.resultSize();

const userName = `${user.firstName} ${user.lastName}`;

await this.gotifyService.sendCheckinNotification(
userName,
user.email,
event.name,
totalScans,
);
} catch (error) {
console.log(`Failed to send Gotify check-in notification: ${error}`);
// Don't fail the check-in if notification fails
}
}
}
1 change: 0 additions & 1 deletion src/modules/registration/registration.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ export class RegistrationController {
};

if (body.status === ApplicationStatus.ACCEPTED) {

const now = new Date();
const oneWeekFromNow = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);

Expand Down
Loading