Additional where param check for a deleted field existence on delete method. #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request addresses an issue in the createDeleteParams function, specifically when attempting to delete a field that has already been marked as deleted. The current implementation sets a new value in the "deletedAt" field (e.g., a new date), which may not be the most intuitive behavior. Instead, it might be more appropriate for Prisma to throw an error. This suggestion may be seen as controversial since Prisma typically returns an error stating the record to delete could not be found, but in our case, it returns an error indicating the record to update was not found. This pull request includes a proposed solution for consideration, aiming to clarify the behavior when repeatedly deleting a record.
Current Behavior and Issue
when the following query is executed:
The actual result is:
However, the expected behavior in case of a deletion attempt on an already deleted record should either be null or an error should be thrown, indicating the operation's invalidity.
Proposed Solution
The issue can be resolved by modifying the function to incorporate a check that prevents updating a field if it has already been updated. This can be achieved by spreading ...{ [field]: null } into the where object of the result parameter.
Envirnoment
Prisma-soft-delete-middleware version: 1.1.2
Prisma version: 5.2.0
Node.js version: 18.12.1