utilities/handler-helper.js
async function _updateHandler(model, _id, request, Log) {
  let payload = Object.assign({}, request.payload)
  try {
    try {
      if (
        model.routeOptions &&
        model.routeOptions.update &&
        model.routeOptions.update.pre
      ) {
        payload = await model.routeOptions.update.pre(
          _id,
          payload,
          request,
          Log
        )
      }
    } catch (err) {
      handleError(
        err,
        'There was a preprocessing error updating the resource.',
        Boom.badRequest,
        Log
      )
    }

    if (config.enableUpdatedAt) {
      payload.updatedAt = new Date()
    }
    let result
    try {
      result = await model.findByIdAndUpdate(_id, payload, {
        runValidators: config.enableMongooseRunValidators
      })
    } catch (err) {
      Log.error(err)
      if (err.code === 11000) {
        throw Boom.conflict('There was a duplicate key error.')
      } else {
        throw Boom.badImplementation(
          'There was an error updating the resource.'
        )
      }
    }
    if (result) {
      let attributes = QueryHelper.createAttributesFilter({}, model, Log)

      result = await model.findOne({ _id: result._id }, attributes).lean()

      try {
        if (
          model.routeOptions &&
          model.routeOptions.update &&
          model.routeOptions.update.post
        ) {
          result = await model.routeOptions.update.post(request, result, Log)
        }
      } catch (err) {
        handleError(
          err,
          'There was a postprocessing error updating the resource.',
          Boom.badRequest,
          Log
        )
      }
      return result
    } else {
      throw Boom.notFound('No resource was found with that id.')
    }
  } catch (err) {
    handleError(err, null, null, Log)
  }
}
async function _updateHandler(model, _id, request, Log) {
  let payload = Object.assign({}, request.payload)
  try {
    try {
      if (
        model.routeOptions &&
        model.routeOptions.update &&
        model.routeOptions.update.pre
      ) {
        payload = await model.routeOptions.update.pre(
          _id,
          payload,
          request,
          Log
        )
      }
    } catch (err) {
      handleError(
        err,
        'There was a preprocessing error updating the resource.',
        Boom.badRequest,
        Log
      )
    }

    if (config.enableUpdatedAt) {
      payload.updatedAt = new Date()
    }
    let result
    try {
      result = await model.findByIdAndUpdate(_id, payload, {
        runValidators: config.enableMongooseRunValidators
      })
    } catch (err) {
      Log.error(err)
      if (err.code === 11000) {
        throw Boom.conflict('There was a duplicate key error.')
      } else {
        throw Boom.badImplementation(
          'There was an error updating the resource.'
        )
      }
    }
    if (result) {
      let attributes = QueryHelper.createAttributesFilter({}, model, Log)

      result = await model.findOne({ _id: result._id }, attributes).lean()

      try {
        if (
          model.routeOptions &&
          model.routeOptions.update &&
          model.routeOptions.update.post
        ) {
          result = await model.routeOptions.update.post(request, result, Log)
        }
      } catch (err) {
        handleError(
          err,
          'There was a postprocessing error updating the resource.',
          Boom.badRequest,
          Log
        )
      }
      return result
    } else {
      throw Boom.notFound('No resource was found with that id.')
    }
  } catch (err) {
    handleError(err, null, null, Log)
  }
}
async function _updateHandler ( model , _id , request , Log ) { let payload = Object . assign ( { } , request . payload ) try { try { if ( model . routeOptions && model . routeOptions . update && model . routeOptions . update . pre ) { payload = await model . routeOptions . update . pre ( _id , payload , request , Log ) } } catch ( err ) { handleError ( err , 'There was a preprocessing error updating the resource.' , Boom . badRequest , Log ) } if ( config . enableUpdatedAt ) { payload . updatedAt = new Date ( ) } let result try { result = await model . findByIdAndUpdate ( _id , payload , { runValidators : config . enableMongooseRunValidators } ) } catch ( err ) { Log . error ( err ) if ( err . code === 11000 ) { throw Boom . conflict ( 'There was a duplicate key error.' ) } else { throw Boom . badImplementation ( 'There was an error updating the resource.' ) } } if ( result ) { let attributes = QueryHelper . createAttributesFilter ( { } , model , Log ) result = await model . findOne ( { _id : result . _id } , attributes ) . lean ( ) try { if ( model . routeOptions && model . routeOptions . update && model . routeOptions . update . post ) { result = await model . routeOptions . update . post ( request , result , Log ) } } catch ( err ) { handleError ( err , 'There was a postprocessing error updating the resource.' , Boom . badRequest , Log ) } return result } else { throw Boom . notFound ( 'No resource was found with that id.' ) } } catch ( err ) { handleError ( err , null , null , Log ) } }
Updates a model document.
@param model: A mongoose model.
@param _id: The document id.
@param request: The Hapi request object, or a container for the wrapper payload.
@param Log: A logging object.
@returns {object} A promise for the resulting model document.
@private
Updates a model document .