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 mutations. #19

Closed hiyaryan closed 9 months ago

hiyaryan commented 9 months ago

This PR adds the ability to update, create, and delete the config from the users Account and/or update (Profile and Password) and delete the entire Account with all associated data in the data base.

This PR introduces the Account Context which is used in the Account React Router route. This is used for batch updating. In the users Account, once they hit the Update button on the review page, the entire Account context is parsed and a request body is built to be sent to the access/:journalId/account endpoint using the PUT method. Authentication is required. The forms are pre-filled the Account data which is called using useEffect on the parent, Account, component.

Batch updating updates the user (first and last names, and email), the users passwords, and the config (optional).

This PR also adds a new util, PopupDialog, which is used to create a popup dialog. This is currently used when the Delete buttons are pressed for Config and Account asking the user if they are sure they wish to proceed.

The backend has been updated accordingly with new PUT and DELETE routes along access/:journalId/account added. The user model has been updated to include a pre-save function that updates the updated_at date. It also attaches a new comparePassword method that is used to re-authenticate the user before setting the new password.

New controllers have been created with respect to the new routes. updateAccount handles the batch updating and deleteItem handles the config and account deletion. When delete is performed on the Account, the url contains the deletionItem, either, config or account determining the conditional logic for the deleteItem controller.