Skip to content
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
wants to merge 13 commits into from

Conversation

davidzlu
Copy link
Collaborator

@davidzlu davidzlu commented Nov 8, 2024

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.

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.
@davidzlu davidzlu added refactor Code refactoring test Add or improve testing labels Nov 8, 2024
@davidzlu davidzlu self-assigned this Nov 8, 2024
@davidzlu davidzlu requested a review from hiyaryan November 8, 2024 22:26
Base automatically changed from 139-read-entry-services to 139-ts-migration November 11, 2024 21:23
@davidzlu davidzlu closed this Nov 12, 2024
@davidzlu
Copy link
Collaborator Author

Will be rebasing this branch onto 139-ts-migration after #187 and #185 merged into it

@davidzlu davidzlu deleted the 139-create-entry-services branch November 12, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code refactoring test Add or improve testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant