A NestJS-based RESTful API , using TypeORM with PostgreSQL. This README provides instructions for contributors to set up the project and details the available API endpoints.
| Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
| POST | /users |
Create a new user | CreateUserDto (name, email, password) |
UserResponseDto (name, email, message) |
| GET | /users/:id |
Get a user by ID | None | UserResponseDto (name, email, message) |
| GET | /users |
Get all users | None | UserResponseDto[] |
| PUT | /users/:id |
Update a user by ID | UpdateUserDto (name?, email?, password?) |
UserResponseDto (name, email, message) |
| DELETE | /users/:id |
Delete a user by ID | None | string (success message) |
curl -X POST http://localhost:3000/users -H "Content-Type: application/json" -d '{ "name": "Oladele20", "email": "samuel@mailto.com","password": "password3" }'Response:
{
"name": "Oladele20",
"email": "samuel@mailto.com",
"message": "user created successfully..."
}curl http://localhost:3000/users/1Response:
{
"name": "Oladele20",
"email": "samuel@mailto.com",
}curl http://localhost:3000/usersResponse:
[
{
"name": "Oladele1",
"email": "stringing20@mail.com"
},
{
"name": "Oladele20",
"email": "samuel@mailto.com"
}
]curl -X PUT http://localhost:3000/users/1 -H "Content-Type: application/json" -d '{"name":"blurbeast"}'Response:
{
"name": "blurbeast",
"email": "samuel@mailto.com",
"message": "user updated successfully"
}curl -X DELETE http://localhost:3000/users/1Response:
"User deleted successfully"- Node.js: v20.x (install via
nvm):curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash nvm install 20 nvm use 20 - PostgreSQL: Install and ensure it’s running:
sudo apt update sudo apt install postgresql postgresql-contrib sudo service postgresql start
- Git: Installed for cloning the repository.
-
Clone the Repository:
git clone https://github.com/your-username/my-fans-backend.git cd my-fans-backend -
Install Dependencies:
npm install
-
Configure Environment: Create a
.envfile in the root directory with the following:DB_HOST=localhost DB_PORT=5432 DB_NAME=my_fans_db DB_USERNAME=postgres DB_PASSWORD=password
-
Start the Application:
npm run start:dev
-
Test APIs: Use the
curlcommands in the API Documentation section to verify endpoints.
Run the unit test suite:
npm testRun the end-to-end suite:
npm run test:e2eThe e2e suite uses a dedicated PostgreSQL test database and does not read your normal DB_* variables. By default it connects to:
TEST_DB_HOST=127.0.0.1
TEST_DB_PORT=5432
TEST_DB_NAME=my_fans_test
TEST_DB_USERNAME=postgres
TEST_DB_PASSWORD=postgres
TEST_JWT_SECRET=test-jwt-secret
TEST_JWT_EXPIRES_IN=1hCreate the database once before running locally:
createdb -h 127.0.0.1 -U postgres my_fans_testOverride the TEST_DB_* variables if your local PostgreSQL user, password, host, or port differs. Test data is truncated between specs.
Populate the local database with test users by running:
npm run seed:devThe script is idempotent — re-running it skips users that already exist.
To wipe the users table first and start fresh:
npm run seed:dev -- --fresh
⚠️ The script refuses to run whenNODE_ENV=production.
| Name | Password | Role (future) | |
|---|---|---|---|
| Fan One | fan1@dev.local | Fan1Pass! | fan |
| Fan Two | fan2@dev.local | Fan2Pass! | fan |
| Creator One | creator1@dev.local | Creator1Pass! | creator |
| Creator Two | creator2@dev.local | Creator2Pass! | creator |
| Admin | admin@dev.local | AdminPass! | admin |
These credentials are development-only and must never be used in production.
- Fork the repository.
- Clone your fork locally:
git clone https://github.com/your-username/my-fans-backend.git
- Create a feature branch:
git checkout -b feature/your-feature
- Make changes and commit:
If Husky linting blocks the commit, bypass temporarily:
git commit -m "Add your feature or fix"git commit -m "Add your feature or fix" --no-verify - Push to your fork:
git push origin feature/your-feature
- Open a Pull Request on the main repository.
- Not-Null Constraint Errors:
- Ensure
CreateUserDtohas valid data forname,email, andpassword. - Check migrations for correct
Usertable schema (NOT NULLconstraints).
- Ensure
- Database Connection Issues:
- Verify
.envvariables (DB_HOST,DB_PORT,DB_NAME,DB_USERNAME,DB_PASSWORD). - Check PostgreSQL status:
sudo service postgresql status
- Verify
MIT License