Skip to content

Commit

Permalink
feat: enforce deadlines in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrastopoulos committed Feb 6, 2025
1 parent e27742b commit 55426d8
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/controllers/ProjectsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getTartanHacks } from "./EventController";
import { findUserTeam } from "./TeamController";
import CheckinItem from "../models/CheckinItem";
import Checkin from "../models/Checkin";
import Settings from "../models/Settings";

const GRAND_PRIZE_NAME = "Scott Krulcik Grand Prize";

Expand Down Expand Up @@ -118,6 +119,18 @@ export const saveProject = async (
return bad(res, "Project already submitted");
}

const expoConfig = await getExpoConfig();
if (!expoConfig) {
return bad(res, "Expo configuration not found");
}

if (new Date() > expoConfig.submissionDeadline) {
return bad(
res,
"Project submission deadline has passed. Please contact the organizers if you need to save your project."
);
}

await Project.findByIdAndUpdate(
id,
{ $set: req.body },
Expand Down Expand Up @@ -400,6 +413,19 @@ export const submitProject = async (
return notFound(res, "Project not found");
}

const expoConfig = await getExpoConfig();

if (!expoConfig) {
return bad(res, "Expo configuration not found");
}

if (new Date() > expoConfig.submissionDeadline) {
return bad(
res,
"Project submission deadline has passed. Please contact the organizers if you need to submit your project."
);
}

await project.updateOne({
$set: { submitted: true },
});
Expand Down Expand Up @@ -465,6 +491,18 @@ export const updateProjectTableNumber = async (
return bad(res, "Project already has a table number");
}

const expoConfig = await getExpoConfig();
if (!expoConfig) {
return bad(res, "Expo configuration not found");
}

if (new Date() > expoConfig.expoStartTime) {
return bad(
res,
"Cannot assign table numbers after expo start time. Please contact the organizers if you need to change your table number."
);
}

await project.updateOne({
$set: { tableNumber },
});
Expand All @@ -483,3 +521,17 @@ export const updateProjectTableNumber = async (
}
}
};

async function getExpoConfig(): Promise<{
expoStartTime: Date;
submissionDeadline: Date;
} | null> {
const settings = await Settings.findOne({});
if (!settings || !settings.expoStartTime || !settings.submissionDeadline) {
return null;
}
return {
expoStartTime: settings.expoStartTime,
submissionDeadline: settings.submissionDeadline,
};
}

0 comments on commit 55426d8

Please sign in to comment.