Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lakshan mean to me but he cant code lol #30

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 13 additions & 13 deletions backend/src/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ router.put('/questions/:questionId/edit', async (req: Request<QuestionRouteParam

const { rowCount } = await db.query(query, args);
if (rowCount === 0) {
res.status(401).json('Question not found!');
res.status(404).json('Question not found!');
return;
}

Expand All @@ -81,13 +81,13 @@ router.put('/comments/:commentId/edit', async (req: Request<CommentRouteParams,
const { commentId } = req.params;

if (!req.body.commentText && !req.body.commentPNG) {
res.status(400).json('No changes made!');
res.status(404).json('No changes made!');
return;
}

const { rowCount } = await editComment(commentId, req.body.commentText, req.body.commentPNG);
if (rowCount === 0) {
res.status(401).json('Question not found!');
res.status(404).json('Question not found!');
return;
}

Expand All @@ -108,7 +108,7 @@ router.patch('/comments/:commentId/delete', async (req: Request<CommentRoutePara

const { rowCount } = await editComment(commentId, '', '');
if (rowCount === 0) {
res.status(401).json('Question not found!');
res.status(404).json('Question not found!');
return;
}

Expand All @@ -125,7 +125,7 @@ router.patch('/comments/:commentId/correct', async (req: Request<CommentRoutePar
WHERE "commentId" = $1
`, [commentId]);
if (rowCount === 0) {
res.status(400).json('Comment not found!');
res.status(404).json('Comment not found!');
return;
}

Expand All @@ -142,7 +142,7 @@ router.patch('/comments/:commentId/endorse', async (req: Request<CommentRoutePar
WHERE "commentId" = $1
`, [commentId]);
if (rowCount === 0) {
res.status(400).json('Comment not found!');
res.status(404).json('Comment not found!');
return;
}

Expand All @@ -159,7 +159,7 @@ router.patch('/comments/:commentId/downvote', async (req: Request<CommentRoutePa
WHERE "commentId" = $1
`, [commentId]);
if (rowCount === 0) {
res.status(400).json('Comment not found!');
res.status(404).json('Comment not found!');
return;
}

Expand All @@ -176,7 +176,7 @@ router.patch('/comments/:commentId/upvote', async (req: Request<CommentRoutePara
WHERE "commentId" = $1
`, [commentId]);
if (rowCount === 0) {
res.status(400).json('Comment not found!');
res.status(404).json('Comment not found!');
return;
}

Expand Down Expand Up @@ -212,20 +212,20 @@ router.post('/comments', async (req: Request<any, any, CommentBodyParams>, res:

const { rowCount } = await db.query(`SELECT "questionId" FROM questions WHERE "questionId" = $1`, [questionId]);
if (rowCount === 0) {
res.status(401).json('Question not found!');
res.status(404).json('Question not found!');
return;
}

// Check parent id
if (parentCommentId) {
const { rowCount, rows } = await db.query<Partial<IComment>>(`SELECT "commentId", "questionId" FROM comments WHERE "commentId" = $1`, [parentCommentId]);
if (rowCount === 0) {
res.status(402).json('Parent comment not found!');
res.status(404).json('Parent comment not found!');
return;
}
const parentComment = rows[0];
if (parentComment.questionId !== questionId) {
res.status(403).json('Parent comment is not from the same question!');
res.status(400).json('Parent comment is not from the same question!');
return;
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ router.post('/questions', async (req: Request<any, any, QuestionBodyParams>, res

const { rowCount } = await db.query(`SELECT "examId" exams WHERE "examId" = $1`, [examId]);
if (rowCount === 0) {
res.status(401).json('Exam not found!');
res.status(404).json('Exam not found!');
return;
}

Expand Down Expand Up @@ -284,7 +284,7 @@ router.post('/exams', async (req: Request<any, any, ExamBodyParams>, res: Respon

const { rowCount } = await db.query(`SELECT "courseCode" courses WHERE "courseCode" = $1`, [courseCode]);
if (rowCount === 0) {
res.status(401).json('Exam not found!');
res.status(404).json('Exam not found!');
return;
}

Expand Down
Loading