Feat/53/needs duplicate prevention #200
Draft
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.
What changed?
Confirms that the required related fields (survey, region and item) are included
Checks for any existing entries with the same values for survey, region, subregion and item
Throws an error if duplicate entry is found and does not create the entry.
Closes #53
How can you test this?
Currently there are no automated tests. Best way to test is by sending post requests via an http client (e.g. Bruno, Postman, Insomnia).
If your local db is empty, using the Content Manager, add several entries in the
Survey
,Region
,Subregion
andItem
collections. Use the Id's from these items in the "connect" parts of the body data listed below.Use the following api for the remaining steps
Request type:
POST
Request url:
http://localhost:1337/api/needs?populate=*
Create a post body that successfully creates an entry.
Send that same post again and confirm that it returns an error and does not create a duplicate entry
Send a post request that is missing one or more required fields. Confirm that this returns an error and does not create an entry. For example, this one does not have a
survey
field:Send a post that has invalid ids for related data. Confirm that this returns an error and does not create an entry