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 and reframing distorted thinking when you've been thinking this way your whole life. The CDJ can help with that 🧠✨ -- v2 is in development!
Entry controller refactoring, moving CRUD operations into entry service file
Fixes build error with User type mismatch in app.ts
Refactors EntryAnalysis and EntryConversation by moving getAnalysisContent and getChatContent into CdGpt service file
Updates jest setup script to deploy memory-mongodb as replica set to support delete unit tests
Entry Controller
The entry controller was a very large file and difficult to test as it combined code for performing CRUD operations on entries with Express error handling, request parsing, and response creation. This PR made the following changes:
Moved code for performing create, update, and deletes on Entry, EntryConversation, and EntryAnalysis into a service layer (/models/services/entry/entry.ts)
Adds unit tests for entry service module
Creates function verifyJournalExists for sharing operation across controller functions
Adds custom types UpdateEntryRequestBody and UpdateChatRequestBody for enforcing types for request.body for different controller functions
Build error in app.ts
There was a tsc error where the user type in the passport and and passport-local-mongoose modules didn't match. I realized this was caused by the way Express.User was getting defined in our custom type declaration file. I changed it so that Express.User extends our UserType in models to resolve the build error.
Refactoring EntryAnalysis and EntryConversation
These models had the functions getAnalysisContent and getChatContent respectively as the interface for getting content from the LLM. However, the functions seemed to overlap a lot and were awkward fits in the model, so I moved them to a new service layer that would act as the interface for all LLM operations, /models/services/CdGpt.ts. I made the following changes:
moving getAnalysisContent and getChatContent into /models/services/CdGpt.ts
refactoring (/models/services/entry/entry.ts) to use /models/services/CdGpt.ts instead of model methods
moved unit tests from models to service module, and updated existing unit tests to use new module
Jest setup script
To support deletes, I had to deploy mongodb as a replica set rather than a standalone instance. This works, but occasionally I get a ECONNRESET error on cleanup. This doesn't affect any of the unit tests, and only occurs after all of them have run. I think it may have something to do with Jest closing before all of the replica instances close, but I haven't confirmed it. This error doesn't appear to break anything in the test suite, and deploying memory mongodb as a replica set is necessary to support deletes.
This PR contains the following changes:
Entry Controller
The entry controller was a very large file and difficult to test as it combined code for performing CRUD operations on entries with Express error handling, request parsing, and response creation. This PR made the following changes:
Build error in app.ts
There was a tsc error where the
user
type in the passport and and passport-local-mongoose modules didn't match. I realized this was caused by the way Express.User was getting defined in our custom type declaration file. I changed it so that Express.User extends our UserType in models to resolve the build error.Refactoring EntryAnalysis and EntryConversation
These models had the functions getAnalysisContent and getChatContent respectively as the interface for getting content from the LLM. However, the functions seemed to overlap a lot and were awkward fits in the model, so I moved them to a new service layer that would act as the interface for all LLM operations, /models/services/CdGpt.ts. I made the following changes:
Jest setup script
To support deletes, I had to deploy mongodb as a replica set rather than a standalone instance. This works, but occasionally I get a ECONNRESET error on cleanup. This doesn't affect any of the unit tests, and only occurs after all of them have run. I think it may have something to do with Jest closing before all of the replica instances close, but I haven't confirmed it. This error doesn't appear to break anything in the test suite, and deploying memory mongodb as a replica set is necessary to support deletes.