deleteResourceHelper

REST API helper function to delete a single document from a collection.

The deleteResourceHelper function accepts an options object with the following properties:

ParameterTypeDescription
optionsDeleteResourceHelperOptions<T>An object that provides configuration options for deleting.
options.modelModel<T>The model used for deleting.
options.intigrityIntegrity[]Related collections to check for relations before deleting.
options.checkSelfbooleanCheck if the ID is the logged-in user.
options.afterFnHook(event: H3Event, resource?: T) => Promise<void>Callback function to run after deleting the resource.

Integrity Object

The Integrity object represents a related collection to check for relations before deleting.

PropertyTypeDescription
modelModel<any>The related model to check for relations.
localFieldstringThe local field in the current model to match with the foreign field in model.
foreignFieldstringThe foreign field in model to match with the local field in the current model.

This table provides an overview of the parameters for the deleteResourceHelper function, including the optional intigrity parameter.

The function may throw the following errors:

  • Error: If the ID is not a valid ObjectId.
  • Error: If the ID is not found.

The function also includes an example usage in the JSDoc comment block.