Skip to content

Commit

Permalink
fix the bug: we should clear all the elements in judging session when…
Browse files Browse the repository at this point in the history
…ever we update the settings
  • Loading branch information
JihengLi committed Sep 9, 2024
1 parent 25d1b98 commit 7bc82c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
16 changes: 2 additions & 14 deletions components/Organizer/ScheduleTab/ScheduleTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,8 @@ const ScheduleTab = () => {
useEffect(() => {
// Exit early if we don't have data yet
if (!judgingSessions) return;

// Sort judging sessions by time
const time = new Date('2022-10-23T11:00:00').getTime();

// Set the data after filtering it by time
setPotentialSchedule(
judgingSessions.filter(judgingSession => {
let time = new Date(judgingSession.time as string);
return (
new Date(hackathonSettings?.JUDGING_START as string) <= time &&
time <= new Date(hackathonSettings?.JUDGING_END as string)
);
})
);
// Set the data
setPotentialSchedule(judgingSessions);
}, [judgingSessions, hackathonSettings]);

// Combine all the loading, null, and error states
Expand Down
2 changes: 2 additions & 0 deletions pages/api/hackathon-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import dbConnect from '../../middleware/database';
import { getSession } from 'next-auth/react';
import hackathon from '../../models/hackathon';
import JudgingSession from '../../models/JudgingSession';

export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
const session = await getSession({ req });
Expand Down Expand Up @@ -60,6 +61,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
}
);

await JudgingSession.remove();
// return the updated hackathon settings
return res.status(200).json(updatedHackathonSettings);
} catch (err) {
Expand Down

0 comments on commit 7bc82c8

Please sign in to comment.