Skip to content

Commit d53d14f

Browse files
feat: minor fixes
1 parent 26f91f6 commit d53d14f

File tree

3 files changed

+56
-28
lines changed

3 files changed

+56
-28
lines changed

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export const NO_OF_EVENTS = 35;
22

33
export const LOCK_SUBMISSIONS = false;
44

5-
export const CURRENT_ROUND = 0;
5+
export const CURRENT_ROUND = 1;

src/pages/api/admin/submission/[id].ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,38 @@ const editSubmission = async (req: NextApiRequest, res: NextApiResponse) => {
2828
try {
2929
const query = req.query;
3030
const { id } = query;
31-
const submission = await Submission.findById(id);
32-
if (submission.status !== req.body.status - 1)
33-
res.status(400).json({
34-
status: 'error',
35-
message: 'Invalid attempt to change the submission status',
36-
});
37-
else if (submission.status !== CURRENT_ROUND - 1) {
31+
const team = await Team.findById(id).populate('submission');
32+
const submission = team.submission;
33+
if (!submission) {
3834
res.status(400).json({
3935
status: 'error',
40-
message: 'Invalid attempt to change the submission status',
36+
message: 'No submission for the team found.',
4137
});
4238
} else {
43-
await Submission.findByIdAndUpdate(id, req.body);
44-
res.status(200).json({
45-
status: 'success',
46-
message: 'Submission updated.',
47-
});
39+
if (submission.status !== req.body.status - 1)
40+
res.status(400).json({
41+
status: 'error',
42+
message: 'Invalid attempt to change the submission status',
43+
});
44+
else if (submission.status !== CURRENT_ROUND - 1) {
45+
res.status(400).json({
46+
status: 'error',
47+
message: 'Invalid attempt to change the submission status',
48+
});
49+
} else {
50+
const editedSubmission = await Submission.findByIdAndUpdate(
51+
id,
52+
req.body
53+
);
54+
res.status(200).json({
55+
status: 'success',
56+
message: 'Submission updated.',
57+
submission: editedSubmission,
58+
});
59+
}
4860
}
49-
} catch {
61+
} catch (err) {
62+
console.log(err);
5063
res.status(500).json({
5164
status: 'success',
5265
message: 'Internal Server Error',

src/pages/hack/admin/team/[id].tsx

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { GetServerSidePropsContext } from 'next';
1313
import getHandler from '@/handlers/getHandler';
1414
import patchHandler from '@/handlers/patchHandler';
1515
import InputField from '@/components/common/InputField';
16+
import { CURRENT_ROUND } from '@/constants';
1617

1718
interface Props {
1819
id: string;
@@ -70,20 +71,30 @@ const ProjectReviewPage = ({ id }: Props) => {
7071
setRounds(updatedRounds);
7172
};
7273

73-
const SaveRoundChangesHandler = () => {
74-
const formData = {
75-
round1Score: rounds[0].score,
76-
round1Judge: session?.user.name,
77-
round2Score: rounds[1].score,
78-
round2Judge: session?.user.name,
79-
round3Score: rounds[2].score,
80-
round3Judge: session?.user.name,
81-
};
82-
const data = patchHandler(
74+
const SaveRoundChangesHandler = async () => {
75+
let formData = {};
76+
if (CURRENT_ROUND === 1) {
77+
formData = {
78+
round1Score: rounds[0].score,
79+
round1Judge: session?.user.name,
80+
};
81+
} else if (CURRENT_ROUND === 2) {
82+
formData = {
83+
round2Score: rounds[1].score,
84+
round2Judge: session?.user.name,
85+
};
86+
} else if (CURRENT_ROUND === 3) {
87+
formData = {
88+
round3Score: rounds[2].score,
89+
round3Judge: session?.user.name,
90+
};
91+
}
92+
93+
const data = await patchHandler(
8394
`${process.env.NEXT_PUBLIC_BASE_URL}/api/admin/submission/${id}`,
8495
formData
8596
);
86-
console.log(rounds);
97+
console.log(data);
8798
};
8899

89100
const handleScoreChange = (index: number, value: number) => {
@@ -247,14 +258,18 @@ const ProjectReviewPage = ({ id }: Props) => {
247258

248259
{/* STRONGLY SUGGESTED MAKE NEW DUPLICATE 2 COMPONENTS BELOW JUST FOR ADMIN PANEL SOLO PROJECT VIEW PAGE CUZ IT WILL HAVE A NEW CHECK KI EVEN SUPER USER CAN VIEW ALL */}
249260
<div className="w-full lg:w-[50%] h-full">
250-
{toggleEdit === 0 ? (
261+
{/* {toggleEdit === 0 ? (
251262
<ViewSubmission
252263
id={id}
253264
toggleEdit={setToggleEdit}
254265
/>
255266
) : (
256267
<EditSubmission id={id} />
257-
)}
268+
)} */}
269+
<ViewSubmission
270+
id={id}
271+
toggleEdit={setToggleEdit}
272+
/>
258273
</div>
259274
</>
260275
)}

0 commit comments

Comments
 (0)