Skip to content
Draft
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
20 changes: 19 additions & 1 deletion services/registration/src/routes/grading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Types } from "mongoose";
import _ from "lodash";

import { ApplicationModel, Essay, StatusType } from "../models/application";
import { ReferralModel, ReferralStatusType } from "../models/referral";
import { GraderModel } from "../models/grader";
import { Review, ReviewModel } from "../models/review";
import { BranchModel, BranchType, GradingGroupType } from "../models/branch";
Expand All @@ -15,6 +16,21 @@ import { getCalibrationMapping } from "../common/adjustScores";
const MAX_REVIEWS_PER_ESSAY = 2;
// NOTE: No. of essays for each application. As such, will need to be updated whenever we add/remove essays.
const ESSAY_COUNT = 4;
const REFERRAL_BONUS = 2;

async function checkForReferralBonus(email?: string, hexathon?: Types.ObjectId) {
if (!email || !hexathon) {
return 0;
}

const referral = await ReferralModel.exists({
hexathon,
"status": ReferralStatusType.SUBMITTED,
"referralData.email": new RegExp(`^${_.escapeRegExp(email.trim())}$`, "i"),
});

return referral ? REFERRAL_BONUS : 0;
}

type AggregatedEssay = {
applicationId: string;
Expand Down Expand Up @@ -304,7 +320,9 @@ gradingRouter.route("/actions/submit-review").post(
if (allEssayReviews.length >= MAX_REVIEWS_PER_ESSAY * ESSAY_COUNT) {
application.gradingComplete = true;
const sumScores = allEssayReviews.reduce((prev, review) => prev + review.adjustedScore, 0);
application.finalScore = sumScores / allEssayReviews.length;
const baseScore = sumScores / allEssayReviews.length;
const referralBonus = await checkForReferralBonus(application);
application.finalScore = baseScore + referralBonus;
await application.save();
}

Expand Down