Skip to content

Commit

Permalink
[backend] Check if problem is solved when fetching problem statement
Browse files Browse the repository at this point in the history
  • Loading branch information
MananGandhi1810 committed Oct 31, 2024
1 parent 2b14255 commit 3843608
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions backend/handlers/problem-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,26 @@ const getProblemStatementByIdHandler = async (req, res) => {
});
}
const { withHidden } = req.query;
const problemStatement = await prisma.problemStatement.findUnique({
var problemStatement = await prisma.problemStatement.findUnique({
where: { id: problemStatementId },
include:
withHidden && req.user.admin
? { testCase: true }
: {
testCase: {
include: {
testCase:
withHidden && req.user.admin
? true
: {
where: { hidden: false },
},
},
_count: {
select: {
submissions: {
where: {
userId: req.user.id,
success: true,
},
},
},
},
},
});
if (!problemStatement) {
return res.status(404).json({
Expand All @@ -59,6 +69,8 @@ const getProblemStatementByIdHandler = async (req, res) => {
data: null,
});
}
problemStatement.solved = problemStatement._count.submissions > 0;
problemStatement._count = undefined;
res.json({
success: true,
message: "Fetched problem statement",
Expand Down

0 comments on commit 3843608

Please sign in to comment.