This module is responsible for handling all exercise related requests
The following routes are handled by this module::
POST /exercise/new - Create a new exercise GET /exercise/ - Get all exercises GET /exercise/:id - Get a particular exercise PATCH /exercise/update/:id - Update a particular exercise DELETE /exercise/delete/:id - Delete a particular exercise POST /exercise/score - Grade or score a particular exercise GET /exercise/submission/:id - Get a particular exercise submission GET /exercise/submission/prev/:exerciseId - Get previous submissions for a particular exercise
Requires
- module:../models/course.models
- module:../utils/errors
Methods
# static addQuestionToExercise(exercise_id, question_id) → {string}
This function adds a question to an exercise.
Parameters:
Name | Type | Description |
---|---|---|
exercise_id |
string
|
|
question_id |
string
|
if an error occured
error
if Exercise not found
NotFoundError
if Question not found
NotFoundError
message
string
# static createExercise(title, description, course_id, course_section_id, duration) → {MongooseObject}
Create new exercise
Parameters:
Name | Type | Description |
---|---|---|
title |
string
|
Exercise title |
description |
string
|
Exercise description |
course_id |
string
|
Course id |
course_section_id |
string
|
Course section id |
duration |
string
|
Course duration in time |
if an error occured
error
if course_id provided and it doesn't match any course in DB
NotFoundError
saved_exercise
MongooseObject
# static deleteExercise(id)
Delete exercise
Doesn't literally delete the exercise, it only makes it unavailable
Parameters:
Name | Type | Description |
---|---|---|
id |
string
|
id of exercise |
if an error occured
error
if exercise not found
NotFoundError
# static getExerciseData(id) → {Object}
Get exercise data
Parameters:
Name | Type | Description |
---|---|---|
id |
string
|
id of the exercise |
if missing required param in request
BadRequestError
if exercise not found
NotFoundError
exercise
Object
# static getExercises(course_id, _id, title, description, duration) → {ArrayObject}
By default it gets all available exercises, if req.body is provided it'll be used as query params to make a more streamlined query result
Parameters:
Name | Type | Description |
---|---|---|
course_id |
string
|
Course id |
_id |
string
|
Exercise id |
title |
string
|
Exercise title |
description |
string
|
Exercise description |
duration |
string
|
Exercise duration |
if an error occured
error
exercises
ArrayObject
# static getPreviousSubmissionsForExercise(exerciseId) → {MongooseObject}
Get result for previously submitted exercises, it all the previously submissions for a particular exercise.
Parameters:
Name | Type | Description |
---|---|---|
exerciseId |
string
|
id of the exercise |
if Exercise not found
NotFoundError
if exerciseId not provided in request params
BadRequestError
submission
MongooseObject
# static getSubmissionData(id) → {Object}
get data for ealier submitted quiz
Parameters:
Name | Type | Description |
---|---|---|
id |
string
|
id of exercise submission |
if submission id not in request param
BadRequestError
if Submission not found
NotFoundError
if user didn't make submission earlier
ForbiddenError
submission
Object
# static removeQuestionFromExercise(question_id) → {string}
Remove question from exercise
Parameters:
Name | Type | Description |
---|---|---|
question_id |
string
|
if Questin not found
NotFoundError
if an error occured
error
message
string
# static scoreExercise(id, submission) → {Object|string}
Score answers for a particular exercise, this function is called when a student submits an exercise for grading, it returns the score and the report for the exercise, the report contains the exercise id, the user id, the score and the submission.
The submission is saved to the database so the user can view all his submissions for a particular exercise.
Parameters:
Name | Type | Description |
---|---|---|
id |
string
|
exercise id |
submission |
Object
|
Object where keys are question_id's and values are selected option |
if an error occured
error
report
Object
report.exercise report.user report.score submission
string
# static updateExercise(id) → {string|object}
This function updates the exercise data, it doesn't update the questions, to update the questions
use module:QuestionController~Questions
Parameters:
Name | Type | Description |
---|---|---|
id |
string
|
id of exercise |
- See:
-
- module:CourseController~updateExerciseQuestions
View Source API/src/controllers/exercise.controllers.js, line 189
if an error occured
error
if exercise not found
NotFoundError
message
string
exercise
object