Refactor package to allow for more modularity #135
Merged
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.
Something that I'd really like to add here is some unit testing, so that we can test that our endpoints are behaving the way that they should be. While this PR doesn't do that, it does set up some of the groundwork - it refactors the overall architecture so that the app is set up via a
createApp
function, and the database connection viagetDatabaseConnection
, so that these can be instantiated in themain.ts
, rather than these being constants that get imported elsewhere. Additionally, each sub-router now exports asetup
function (in addition to the router object itself) that takes in the app and the database and does whatever setup is necessary (currently, initializing models and setting up associations). This is called during the app setup inmain.ts
.I've also added in some testing dependencies and a simple test here, but I'll actually set up the testing CI later. I mostly want to having this working and merged in because rebasing against changes to the main branch would inevitably be annoying.