deleteResourceHelper
REST API helper function to delete a single document from a collection.
The deleteResourceHelper
function accepts an options object with the following properties:
Parameter | Type | Description |
---|---|---|
options | DeleteResourceHelperOptions<T> | An object that provides configuration options for deleting. |
options.model | Model<T> | The model used for deleting. |
options.intigrity | Integrity[] | Related collections to check for relations before deleting. |
options.checkSelf | boolean | Check 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.
Property | Type | Description |
---|---|---|
model | Model<any> | The related model to check for relations. |
localField | string | The local field in the current model to match with the foreign field in model . |
foreignField | string | The 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.