utilities/handler-helper.js
async function _deleteManyHandler(model, request, Log) {
  try {
    // EXPL: make a copy of the payload so that request.payload remains unchanged
    let payload = request.payload.map(item => {
      return _.isObject(item) ? _.assignIn({}, item) : item
    })
    let promises = []
    for (let arg of payload) {
      if (JoiMongooseHelper.isObjectId(arg)) {
        promises.push(_deleteOneHandler(model, arg, false, request, Log))
      } else {
        promises.push(
          _deleteOneHandler(model, arg._id, arg.hardDelete, request, Log)
        )
      }
    }

    await Promise.all(promises)
    return true
  } catch (err) {
    handleError(err, null, null, Log)
  }
}
async function _deleteManyHandler(model, request, Log) {
  try {
    // EXPL: make a copy of the payload so that request.payload remains unchanged
    let payload = request.payload.map(item => {
      return _.isObject(item) ? _.assignIn({}, item) : item
    })
    let promises = []
    for (let arg of payload) {
      if (JoiMongooseHelper.isObjectId(arg)) {
        promises.push(_deleteOneHandler(model, arg, false, request, Log))
      } else {
        promises.push(
          _deleteOneHandler(model, arg._id, arg.hardDelete, request, Log)
        )
      }
    }

    await Promise.all(promises)
    return true
  } catch (err) {
    handleError(err, null, null, Log)
  }
}
async function _deleteManyHandler ( model , request , Log ) { try { // EXPL: make a copy of the payload so that request.payload remains unchanged let payload = request . payload . map ( item => { return _ . isObject ( item ) ? _ . assignIn ( { } , item ) : item } ) let promises = [ ] for ( let arg of payload ) { if ( JoiMongooseHelper . isObjectId ( arg ) ) { promises . push ( _deleteOneHandler ( model , arg , false , request , Log ) ) } else { promises . push ( _deleteOneHandler ( model , arg . _id , arg . hardDelete , request , Log ) ) } } await Promise . all ( promises ) return true } catch ( err ) { handleError ( err , null , null , Log ) } }
Deletes multiple documents.
@param model: A mongoose model.
@param request: The Hapi request object, or a container for the wrapper payload.
@param Log: A logging object.
@returns {object} A promise returning true if the delete succeeds.
@private
 TODO: prevent Promise.all from catching first error and returning early. Catch individual errors and return a list TODO(cont) of ids that failed
Deletes multiple documents .