CodeYourFuture / CodeYourFuture/scot-min-imece
Add new profile should detect and handle duplicate email addresses
- Dominant language
- JavaScript
- Stars
- 1
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
The email address is marked as unique in the database schema, so an attempt to create a profile with an existing email address will cause a server error (with a 500 status code) and the client will report a failure and say "please try again". Instead the server should
1. Check for a duplicate email address
2. Send suitable error message in the response with an appropriate error response code (probably 422 https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422).
3. The client should report the given message to the user if it detects this response code.
Checking for a duplicate address can be done by modifying the `INSERT` statement and adding a ` WHERE NOT EXISTS` clause to check the email. If the server doesn't insert the row, the returned [`result.rowCount`](https://node-postgres.com/api/result) value will be 0, indicating that the email address already exists.
Contributor guide
Assessment
This issue has not been assessed yet.