-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: create entry services refactoring #189
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added tests for getting and creating entries. getAnalysisContent in EntryAnalysis was breaking test suite for some reason. It appeared that using Config in the method caused an issue with the model compilation within Jest runtime, but I'm not sure why. I pulled it out from the file and put it in the entry services to fix it. In-progress, so may be broken.
Added JSDocs for functions in entry services and broke up createEntryAnalysis into 2 functions.
Refactored entry controllers to move read calls into functions in entry services
To limit the scope of this branch, I reverted changes I made to the createEntry function in the entry contorllers to match the 139-ts-migration branch
The Passport module needs to be aware of our implementation of users as defined in the User model. This was partially implemented by extending Express.User to have an id property in backend/src/types/express/index.d.ts. The reason for adding just the id was that it was the only property getting used in the access controller. However, this caused issues in app.ts because it expects Express.User to match our User model type. This commit extends Express.User with UserType, which lets Passport access our User definition. It also cleans up type annotations affected by this change.
Using validateEntryAnalysis in the middle of createEntry wasn't doing any useful work because users don't submit content for EntryAnalysis, so there was nothing to validate from the request.
Refactored createEntry handler in entry controller to extract code for creating Entry and EntryAnalysis together, and added unit tests for new function.
Having createEntry handle errors from the analysis completion was making it difficult to disentangle making the Entry and EntryAnalysis from terminating the express request. There were a few ways of resolving this, but I decided to push the error handling into the entry service module, and have it return an error message. This way I could simplify the flow in the controller.
Moved code for creating EntryConversation into entry service module and refactored things.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR refactors create operations in controllers/entry into separate functions and moves them to a new file /models/services/entry/entry.ts. It also adds unit tests for the create service functions.
This PR also resolves a build error in app.ts. Previously there was an error due to a mismatch between the Express.User type defined in our custom type declaration file, and the Express.User type defined in the passport library. To resolve this, I had the custom type extend our UserType in the type declaration file.