-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Result Viewing and Custom Team Assignment
Bug found: I think the questions on creation that don't have score aren't saving, check this.
- Loading branch information
Showing
24 changed files
with
1,700 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// controllers/assessmentResultController.ts | ||
|
||
import { Request, Response } from 'express'; | ||
import { | ||
getOrCreateAssessmentResults, | ||
recalculateResult, | ||
checkMarkingCompletion, | ||
} from '../services/assessmentResultService'; | ||
import { BadRequestError, NotFoundError } from '../services/errors'; | ||
|
||
/** | ||
* Controller to retrieve or create AssessmentResults for an assessment. | ||
* Route: GET /api/assessment-results/:assessmentId | ||
*/ | ||
export const getOrCreateAssessmentResultsController = async ( | ||
req: Request, | ||
res: Response, | ||
) => { | ||
const { assessmentId } = req.params; | ||
|
||
try { | ||
const assessmentResults = await getOrCreateAssessmentResults(assessmentId); | ||
res.status(200).json({ | ||
success: true, | ||
data: assessmentResults, | ||
}); | ||
} catch (error) { | ||
if (error instanceof BadRequestError) { | ||
res.status(400).json({ error: error.message }); | ||
} else if (error instanceof NotFoundError) { | ||
res.status(404).json({ error: error.message }); | ||
} else { | ||
console.error('Error retrieving or creating AssessmentResults:', error); | ||
res.status(500).json({ error: 'Failed to retrieve or create AssessmentResults' }); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Controller to recalculate the average score of an AssessmentResult. | ||
* Route: POST /api/assessment-results/:resultId/recalculate | ||
*/ | ||
export const recalculateResultController = async ( | ||
req: Request, | ||
res: Response, | ||
) => { | ||
const { resultId } = req.params; | ||
|
||
try { | ||
await recalculateResult(resultId); | ||
res.status(200).json({ | ||
success: true, | ||
message: 'Average score recalculated successfully.', | ||
}); | ||
} catch (error) { | ||
if (error instanceof NotFoundError) { | ||
res.status(404).json({ error: error.message }); | ||
} else { | ||
console.error('Error recalculating AssessmentResult:', error); | ||
res.status(500).json({ error: 'Failed to recalculate AssessmentResult' }); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Controller to check marking completion for an assessment. | ||
* Route: GET /api/assessment-results/:assessmentId/check-marking-completion | ||
*/ | ||
export const checkMarkingCompletionController = async ( | ||
req: Request, | ||
res: Response, | ||
) => { | ||
const { assessmentId } = req.params; | ||
|
||
try { | ||
const unmarkedTeams = await checkMarkingCompletion(assessmentId); | ||
res.status(200).json({ | ||
success: true, | ||
data: unmarkedTeams, | ||
}); | ||
} catch (error) { | ||
if (error instanceof NotFoundError) { | ||
res.status(404).json({ error: error.message }); | ||
} else { | ||
console.error('Error checking marking completion:', error); | ||
res.status(500).json({ error: 'Failed to check marking completion' }); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.