This project implements a simplified REST API for managing game packs. It is written in TypeScript using the NestJS framework and uses PostgreSQL as the database.
-
Clone the repository:
git clone https://github.com/tryshank/game-packs-api.git cd game-packs-api
-
Install dependencies:
pnpm install
-
Create environment files:
-
.env
(for production):POSTGRES_USER=tocabocauser POSTGRES_PASSWORD=securepassword POSTGRES_DB=tocabocadb DATABASE_URL=postgres://tocabocauser:securepassword@db:5432/tocabocadb APP_PORT=8080
-
.env.test
(for testing):POSTGRES_USER=testuser POSTGRES_PASSWORD=testpassword POSTGRES_DB=testdb DATABASE_URL=postgres://testuser:testpassword@db:5432/testdb APP_PORT=8081
-
-
Run the application using Docker Compose:
docker-compose up --build
-
Run the e2e tests using Docker Compose:
docker-compose -f docker-compose.e2e.yml up --build
-
POST
/packs
- Saves a pack to the database.- Request body example:
{ "id": "pack.school", "packName": "The School Pack", "active": true, "price": 10, "content": ["furniture.whiteboard"], "childPackIds": ["pack.classroom", "pack.playground"] }
- Example
curl
command:curl -X POST http://localhost:8080/packs \ -H "Content-Type: application/json" \ -d '{ "id": "pack.school", "packName": "The School Pack", "active": true, "price": 10, "content": ["furniture.whiteboard"], "childPackIds": ["pack.classroom", "pack.playground"] }'
- Request body example:
-
GET
/packs
- Returns all packs that are in the database.- Response example:
[ { "id": "pack.school", "packName": "The School Pack", "active": true, "price": 10, "content": ["furniture.whiteboard"], "childPackIds": ["pack.classroom", "pack.playground"] } ]
- Example
curl
command:curl -X GET http://localhost:8080/packs
- Response example:
-
GET
/packs/:id/content
- Returns a flat, unique list of allcontent
a pack contains, including the contents of its child packs.- Response example:
["furniture.whiteboard", "furniture.desk", "toy.ball"]
- Example
curl
command:curl -X GET http://localhost:8080/packs/pack.school/content
- Response example:
-
Create a child pack:
curl -X POST http://localhost:8080/packs \ -H "Content-Type: application/json" \ -d '{ "id": "pack.classroom", "packName": "The Classroom Pack", "active": true, "price": 5, "content": ["furniture.desk"], "childPackIds": [] }'
-
Create a parent pack that includes the child pack:
curl -X POST http://localhost:8080/packs \ -H "Content-Type: application/json" \ -d '{ "id": "pack.school", "packName": "The School Pack", "active": true, "price": 10, "content": ["furniture.whiteboard", "toy.ball"], "childPackIds": ["pack.classroom"] }'
The API documentation is available via Swagger. Once the application is running, you can access the documentation at:
http://localhost:8080/api
To run the tests, use the following command:
pnpm run test
DATABASE_URL
: Connection string for the PostgreSQL database.APP_PORT
: Port for the application to run on.
- Service: Node, NestJS
- Database: PostgreSQL
- Testing: Jest
- This project is configured to use
pnpm
for package management. - The Docker setup ensures that both the service and the database can be started with a single
docker-compose up
command. - The code includes unit tests for the service and controller layers to ensure functionality.
- Ensure
synchronize
is set tofalse
in production for TypeORM to avoid accidental schema changes. Use migrations instead.
- Written in TypeScript.
- Includes all expected endpoints.
- Has sufficient tests that are passing.
- Has sufficient documentation.
- Can be started with a single
docker-compose up
command.