cosmicds / cds-api

API for accessing the CosmicDS database
GNU General Public License v3.0
0 stars 3 forks source link

Refactor package to allow for more modularity #135

Closed Carifio24 closed 2 weeks ago

Carifio24 commented 2 weeks ago

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 via getDatabaseConnection, so that these can be instantiated in the main.ts, rather than these being constants that get imported elsewhere. Additionally, each sub-router now exports a setup 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 in main.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.