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

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