server/api/exams/exams.controller.js
/**
 * Add a comment to an exam. The request body should contain the following:
 * - comment: the text of the comment
 *
 * @param {Koa context} ctx
 * @returns The updated exam
 */
Add a comment to an exam. The request body should contain the following:
- comment: the text of the comment

@param {Koa context} ctx
@returns The updated exam
Add a comment to an exam . The request body should contain the following : - comment : the text of the comment @param { Koa context } ctx @returns The updated exam
async function addComment (ctx) {
  const examID = ctx.params.examID;
  const text = ctx.request.body.comment;
  ctx.state.exam.comments.push({
    addedAt: new Date(),
    body: text
  });
  try {
    await ctx.state.exam.save();
  } catch (e) {
    logger.error(
      `Failed to save exam ${examID} for ${ctx.state.user.rcs_id}: ${e}`
    );
    return ctx.badRequest('There was an error adding the comment.');
  }
  ctx.ok({ updatedExam: ctx.state.exam });
}
async function addComment ( ctx ) { const examID = ctx . params . examID ; const text = ctx . request . body . comment ; ctx . state . exam . comments . push ( { addedAt : new Date ( ) , body : text } ) ; try { await ctx . state . exam . save ( ) ; } catch ( e ) { logger . error ( ` ${ examID } ${ ctx . state . user . rcs_id } ${ e } ` ) ; return ctx . badRequest ( 'There was an error adding the comment.' ) ; } ctx . ok ( { updatedExam : ctx . state . exam } ) ; }
Add a comment to an exam.
Add a comment to an exam .
// Add comment