server/api/blocks/blocks.controller.js
/**
 * Edit a work block by changing the start and end times.
 * The request body should contain:
 * - startTime
 * - endTime
 * - assessmentTyoe
 *
 * @param {Koa context} ctx
 * @returns Updated assessment
 *
 * PATCH /:blockID
 */
Edit a work block by changing the start and end times.
The request body should contain:
- startTime
- endTime
- assessmentTyoe

@param {Koa context} ctx
@returns Updated assessment

PATCH /:blockID
Edit a work block by changing the start and end times . The request body should contain : - startTime - endTime - assessmentTyoe @param { Koa context } ctx @returns Updated assessment PATCH / : blockID
async function editWorkBlock (ctx) {
  const { assessmentType, assessmentID, blockID } = ctx.params;
  const { startTime, endTime } = ctx.request.body;
  const editedBlock = await Block.findOne({
    _student: ctx.state.user._id,
    _id: blockID
  });
  editedBlock.set({ startTime, endTime });
  try {
    await editedBlock.save();
  } catch (e) {
    logger.error(
      `Failed to edit work block for ${ctx.state.user.rcs_id}: ${e}`
    );
    return ctx.badRequest('There was an error updatng the work block.');
  }
  let assessment;
  try {
    assessment = await (assessmentType === 'assignment' ? Assignment : Exam)
      .findOne({
        _student: ctx.state.user._id,
        _id: assessmentID
      })
      .populate('_blocks');
  } catch (e) {
    logger.error(
      `Failed to get ${assessmentType} for work block edit for ${
        ctx.state.user.rcs_id
      }: ${e}`
    );
    return ctx.internalServerError(
      'There was an error editing the work block.'
    );
  }
  logger.info(`Edited work block for ${ctx.state.user.rcs_id}`);
  return ctx.ok({
    ['updated' +
    (assessmentType === 'assignment' ? 'Assignment' : 'Exam')]: assessment
  });
}
async function editWorkBlock ( ctx ) { const { assessmentType , assessmentID , blockID } = ctx . params ; const { startTime , endTime } = ctx . request . body ; const editedBlock = await Block . findOne ( { _student : ctx . state . user . _id , _id : blockID } ) ; editedBlock . set ( { startTime , endTime } ) ; try { await editedBlock . save ( ) ; } catch ( e ) { logger . error ( ` ${ ctx . state . user . rcs_id } ${ e } ` ) ; return ctx . badRequest ( 'There was an error updatng the work block.' ) ; } let assessment ; try { assessment = await ( assessmentType === 'assignment' ? Assignment : Exam ) . findOne ( { _student : ctx . state . user . _id , _id : assessmentID } ) . populate ( '_blocks' ) ; } catch ( e ) { logger . error ( ` ${ assessmentType } ${ ctx . state . user . rcs_id } ${ e } ` ) ; return ctx . internalServerError ( 'There was an error editing the work block.' ) ; } logger . info ( ` ${ ctx . state . user . rcs_id } ` ) ; return ctx . ok ( { [ 'updated' + ( assessmentType === 'assignment' ? 'Assignment' : 'Exam' ) ] : assessment } ) ; }
Edit a work block by changing the start and end times.
Edit a work block by changing the start and end times .
// Get assessment // eslint-disable-next-line standard/computed-property-even-spacing