hiyaryan / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling distorted thinking and finding alternative modes of thought (i.e. reframing) while cognitive distortions are occurring. The CDJ does that work for you. -- The CDJ is in beta testing!!
https://thecdj.app
3 stars 0 forks source link

Add account validations. #20

Closed hiyaryan closed 9 months ago

hiyaryan commented 9 months ago

This PR adds validations to account updates. It updates the user model to adding a new account validation joi schema. It also refactors the file to prevent duplication by using utility functions to determine when fields are required such as on login and registration (on account update, not all fields are required but should conform to the same patterns and requirements). This validation schema is used in a new validateAccount middleware added to the access/:journalId/account, PUT, endpoint.

This PR also updates the Account component. On update, the Account context is reset and a call is made to the server to retrieve the updated account. Additionally, whenever the Finish button is pressed, the Account context is filtered. This filtering compares the Account context (the items to be updated) against the data retrieved from the server, and deletes any matching properties. Prior to this, the Review page would show fields with data already existing in the database and allowing Update to be pressed. The last commit prevents this unnecessary request.