Skip to content

Commit

Permalink
Added submitReview route
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRibcage committed Jun 26, 2024
1 parent 6961e05 commit 8c114b9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions config/express/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import express, { Request, Response } from "express";
import { ReviewsService } from "../../app/challenges-platform";
import { Status } from "../../app/challenges-platform/models/index";
import { db } from "../../db";
import { challenges } from "../../db/schema";

Expand All @@ -16,7 +18,32 @@ const getChallenges = async (_: Request, response: Response) => {
response.json(result);
};

const submitReview = async (request: Request, response: Response) => {
if (!request.body.review) {
response.status(400).json({ message: "Invalid request" });
return;
}

const review = request.body.review;
const { submissionId, comment } = review;
let sentStatus = review.status;

if ((sentStatus !== "APPROVED" && sentStatus !== "REJECTED") || !submissionId || !comment) {
response.status(400).json({ message: "Invalid request" });
return;
}
const status = sentStatus === "APPROVED" ? Status.APPROVED : Status.REJECTED;

const result = await ReviewsService.create(status, submissionId, comment);
if (result.err) {
response.status(500).json({ message: "Failed to create review" });
return;
}
response.json(result);
}

router.get("/", getAPIRoot);
router.get("/challenges", getChallenges);
router.post("/reviews", submitReview);

export default router;

0 comments on commit 8c114b9

Please sign in to comment.