OpenTree-Education / rhizone-lms

A learning management system focused on self-reflection.
https://rhi.zone
BSD 3-Clause Clear License
14 stars 7 forks source link

Implement functionality for the GET /program/:programAssessmentId/submissions/new route and accompanying service file functions #539

Closed ZeyuanLi16 closed 1 year ago

ZeyuanLi16 commented 1 year ago

Describe the Feature / Enhancement

The GET /program/:programAssessmentId/submissions/new route needs to be implemented and fully tested. The GET /program/:programAssessmentId/submissions/new route creates a new assessment submission for a program assessment if the participant is allowed to do so.

There needs to be a test coverage for the GET /program/:programAssessmentId/submissions/new route and the service file functions it needs. We need to test this route to ensure the code written for the test will behave as expected by the protocol we previously defined.

This issue continues the work from issue #515.

Additional Details and Resources

This route requires the principal ID (the user ID) from the session information, this route expects a program assessment ID in the URL as a URL parameter, and expects nothing in the body of the request. The response should contain the following:

Facilitator

This should return an UnauthorizedError. Facilitators shouldn't have access to this route.

Participant

If the participant has not submitted the max_num_submissions for a curriculum assessment for this program assessment, and there exists no AssessmentSubmission currently in the "Opened" or "In Progress" states by this user for this program assessment, and the due date for this program assessment has not passed, return the following:

res.json(
  itemEnvelope({
    curriculum_assessment: CurriculumAssessment (with 'questions' and 'answers' but not the correct answers),
    program_assessment: ProgramAssessment,
    principal_program_role: 'Participant',
    submission: a newly-created AssessmentSubmission
  })
);

If the participant has an AssessmentSubmission currently in the "Opened" or "In Progress" for this program assessment and the due date for this program assessment has not passed, return the following:

res.json(
  itemEnvelope({
    curriculum_assessment: CurriculumAssessment (with 'questions' and 'answers' but not the correct answers),
    program_assessment: ProgramAssessment,
    principal_program_role: 'Participant',
    submission: the existing AssessmentSubmission
  })
);

Else, return a ForbiddenError.

export class ForbiddenError extends HttpError {}
ForbiddenError.prototype.message = 'Access to this resource is not allowed.';
ForbiddenError.prototype.status = 403;
else if (new Date() > due_date) {
  throw new ForbiddenError(`You may not create a new assessment submission because the due date has passed.`);
} else if (numSubmissions > max_num_submissions) {
  throw new ForbiddenError(`You have reached the maximum number of submissions for this assessment.`);
} else {
  throw new ForbiddenError();
}

Correct Project Selected

Labels