utilities/handler-helper.js
async function _deleteOneHandler(model, _id, hardDelete, request, Log) {
  try {
    try {
      if (
        model.routeOptions &&
        model.routeOptions.delete &&
        model.routeOptions.delete.pre
      ) {
        await model.routeOptions.delete.pre(_id, hardDelete, request, Log)
      }
    } catch (err) {
      handleError(
        err,
        'There was a preprocessing error deleting the resource.',
        Boom.badRequest,
        Log
      )
    }
    let deleted

    try {
      if (config.enableSoftDelete && !hardDelete) {
        let payload = { isDeleted: true }
        if (config.enableDeletedAt) {
          payload.deletedAt = new Date()
        }
        if (config.enableDeletedBy && config.enableSoftDelete) {
          let deletedBy =
            request.payload.deletedBy || request.payload[0].deletedBy
          if (deletedBy) {
            payload.deletedBy = deletedBy
          }
        }
        deleted = await model.findByIdAndUpdate(_id, payload, {
          new: true,
          runValidators: config.enableMongooseRunValidators
        })
      } else {
        deleted = await model.findByIdAndRemove(_id)
      }
    } catch (err) {
      handleError(
        err,
        'There was an error deleting the resource.',
        Boom.badImplementation,
        Log
      )
    }
    // TODO: clean up associations/set rules for ON DELETE CASCADE/etc.
    if (deleted) {
      // TODO: add eventLogs

      try {
        if (
          model.routeOptions &&
          model.routeOptions.delete &&
          model.routeOptions.delete.post
        ) {
          await model.routeOptions.delete.post(
            hardDelete,
            deleted,
            request,
            Log
          )
        }
      } catch (err) {
        handleError(
          err,
          'There was a postprocessing error deleting the resource.',
          Boom.badRequest,
          Log
        )
      }
      return true
    } else {
      throw Boom.notFound('No resource was found with that id.')
    }
  } catch (err) {
    handleError(err, null, null, Log)
  }
}
async function _deleteOneHandler(model, _id, hardDelete, request, Log) {
  try {
    try {
      if (
        model.routeOptions &&
        model.routeOptions.delete &&
        model.routeOptions.delete.pre
      ) {
        await model.routeOptions.delete.pre(_id, hardDelete, request, Log)
      }
    } catch (err) {
      handleError(
        err,
        'There was a preprocessing error deleting the resource.',
        Boom.badRequest,
        Log
      )
    }
    let deleted

    try {
      if (config.enableSoftDelete && !hardDelete) {
        let payload = { isDeleted: true }
        if (config.enableDeletedAt) {
          payload.deletedAt = new Date()
        }
        if (config.enableDeletedBy && config.enableSoftDelete) {
          let deletedBy =
            request.payload.deletedBy || request.payload[0].deletedBy
          if (deletedBy) {
            payload.deletedBy = deletedBy
          }
        }
        deleted = await model.findByIdAndUpdate(_id, payload, {
          new: true,
          runValidators: config.enableMongooseRunValidators
        })
      } else {
        deleted = await model.findByIdAndRemove(_id)
      }
    } catch (err) {
      handleError(
        err,
        'There was an error deleting the resource.',
        Boom.badImplementation,
        Log
      )
    }
    // TODO: clean up associations/set rules for ON DELETE CASCADE/etc.
    if (deleted) {
      // TODO: add eventLogs

      try {
        if (
          model.routeOptions &&
          model.routeOptions.delete &&
          model.routeOptions.delete.post
        ) {
          await model.routeOptions.delete.post(
            hardDelete,
            deleted,
            request,
            Log
          )
        }
      } catch (err) {
        handleError(
          err,
          'There was a postprocessing error deleting the resource.',
          Boom.badRequest,
          Log
        )
      }
      return true
    } else {
      throw Boom.notFound('No resource was found with that id.')
    }
  } catch (err) {
    handleError(err, null, null, Log)
  }
}
async function _deleteOneHandler ( model , _id , hardDelete , request , Log ) { try { try { if ( model . routeOptions && model . routeOptions . delete && model . routeOptions . delete . pre ) { await model . routeOptions . delete . pre ( _id , hardDelete , request , Log ) } } catch ( err ) { handleError ( err , 'There was a preprocessing error deleting the resource.' , Boom . badRequest , Log ) } let deleted try { if ( config . enableSoftDelete && ! hardDelete ) { let payload = { isDeleted : true } if ( config . enableDeletedAt ) { payload . deletedAt = new Date ( ) } if ( config . enableDeletedBy && config . enableSoftDelete ) { let deletedBy = request . payload . deletedBy || request . payload [ 0 ] . deletedBy if ( deletedBy ) { payload . deletedBy = deletedBy } } deleted = await model . findByIdAndUpdate ( _id , payload , { new : true , runValidators : config . enableMongooseRunValidators } ) } else { deleted = await model . findByIdAndRemove ( _id ) } } catch ( err ) { handleError ( err , 'There was an error deleting the resource.' , Boom . badImplementation , Log ) } // TODO: clean up associations/set rules for ON DELETE CASCADE/etc. if ( deleted ) { // TODO: add eventLogs try { if ( model . routeOptions && model . routeOptions . delete && model . routeOptions . delete . post ) { await model . routeOptions . delete . post ( hardDelete , deleted , request , Log ) } } catch ( err ) { handleError ( err , 'There was a postprocessing error deleting the resource.' , Boom . badRequest , Log ) } return true } else { throw Boom . notFound ( 'No resource was found with that id.' ) } } catch ( err ) { handleError ( err , null , null , Log ) } }
Deletes a model document
@param model: A mongoose model.
@param _id: The document id.
@param hardDelete: Flag used to determine a soft or hard delete.
@param request: The Hapi request object.
@param Log: A logging object.
@returns {object} A promise returning true if the delete succeeds.
@private
 TODO: only update "deleteAt" the first time a document is deleted
Deletes a model document