Skip to content

Commit

Permalink
feat: checkers added
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratham-Mishra04 committed Jun 7, 2023
1 parent 77c0e1d commit df86ce2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
Binary file not shown.
47 changes: 30 additions & 17 deletions src/pages/api/submission/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,39 @@ const addSubmission = async (req: NextApiRequest, res: NextApiResponse) => {
};

const editSubmission = async (req: NextApiRequest, res: NextApiResponse) => {
try {
if (LOCK_SUBMISSIONS)
res.status(201).json({
status: 'error',
message: 'Submissions are now locked.',
});
else {
await Submission.findByIdAndUpdate(req.team.submission, req.body);
const validationRes = editSubmissionSchema.safeParse(req.body);
if (!validationRes.success)
res.status(400).json({
status: 'error',
message:
'Payload Validation Failed: ' +
validationRes.error.issues[0].message,
});
else {
try {
if (LOCK_SUBMISSIONS)
res.status(201).json({
status: 'error',
message: 'Submissions are now locked.',
});
else {
await Submission.findByIdAndUpdate(
req.team.submission,
req.body
);

res.status(201).json({
status: 'success',
message: 'Successfully edited the submission.',
res.status(201).json({
status: 'success',
message: 'Successfully edited the submission.',
});
}
} catch (err) {
console.log(err);
res.status(500).json({
status: 'error',
message: 'Internal server error',
});
}
} catch (err) {
console.log(err);
res.status(500).json({
status: 'error',
message: 'Internal server error',
});
}
};

Expand Down
14 changes: 12 additions & 2 deletions src/schemas/submissionRequestSechemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ export const addSubmissionSchema = z

export const editSubmissionSchema = z
.object({
title: z.string(),
description: z.string().max(100),
links: z.array(z.string()).max(5),
links: z
.array(
z
.string()
.regex(
/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/
)
)
.max(5),
files: z.array(z.string()),
})
.partial();
.strict();
6 changes: 5 additions & 1 deletion src/sections/sdg-view-team-page-sections/edit-submission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const EditSubmission = ({ toggleEdit }: ViewSubmissionProps) => {
const formData = {
title: projectName,
description: projectDescription,
links: links,
links: links || [],
files: files,
};

const res = await patchHandler(
Expand Down Expand Up @@ -99,6 +100,9 @@ const EditSubmission = ({ toggleEdit }: ViewSubmissionProps) => {
const toaster = Toaster.startLoad();

const formData = {
title: projectName,
description: projectDescription,
links: links || [],
files: newFiles,
};

Expand Down

0 comments on commit df86ce2

Please sign in to comment.