diff --git a/src/modules/analytics/analytics.controller.ts b/src/modules/analytics/analytics.controller.ts index 53a270fd..a28726b9 100644 --- a/src/modules/analytics/analytics.controller.ts +++ b/src/modules/analytics/analytics.controller.ts @@ -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"] }, ]; @@ -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) }; @@ -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( @@ -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); diff --git a/src/modules/event/event.controller.ts b/src/modules/event/event.controller.ts index ac4ccd62..1204e92d 100644 --- a/src/modules/event/event.controller.ts +++ b/src/modules/event/event.controller.ts @@ -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); @@ -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", @@ -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( @@ -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( @@ -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 - } } } diff --git a/src/modules/registration/registration.controller.ts b/src/modules/registration/registration.controller.ts index b51123ba..498e14bb 100644 --- a/src/modules/registration/registration.controller.ts +++ b/src/modules/registration/registration.controller.ts @@ -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);