This implementation uses MySQL for the database, following the relational model outlined below:
The schema definition can be found in /db/schema.sql.
The Course table holds the main course details, while the Module table supports infinite nesting, enabling both simple and complex course structures. Each module is linked to a course and can have a parent module, allowing for a hierarchical structure. The Lesson table stores the lessons within modules, and the Completion table tracks user progress by recording which lessons a user has completed. Foreign key relationships ensure that when a course, module, or lesson is deleted, the associated data is automatically cleaned up to maintain data integrity.
- Services: Implemented services for managing courses, modules, lessons, and completions based on the methods defined in the original template's controllers.
- TypeORM: Used TypeORM to define repositories for the models and applied the necessary decorators based on the logical model.
- Redis Caching: Integrated Redis to cache GET responses for modules, with a cache expiration of 60 minutes.
- Tests: Added integration tests for the courses API as requested.
Additionally, I’ve included a .env-template with all the required environment variables for the project and Docker. The values can be based on the defaults for MySQL, Express, and Redis (host redis, port 6379).
I also updated the Docker Compose file to include Redis setup and environment variable configuration.
To run the project, you need Docker and Docker Compose installed. Then, follow these steps:
Before trying to build the services from the docker-compose file, it is neccesary to add the variables FROM .env file
- Start Docker:
# MacOS
make
# Windows
docker-compose --env-file .env up -d --build- Install Dependencies:
# MacOS
make install
# Windows
docker-compose exec node npm install- Run the Node Server:
# MacOS
make run
# Windows
docker-compose exec node npm run dev- If desired, can populate the database with example cases, and want to test API
# Windows
docker-compose exec node npx ts-node src/scripts/seedDatabase.ts- Run the Test Suite:
# MacOS
make test
# Windows
docker-compose exec node npm run testTests results

