This backend application is built with NestJS and TypeScript, designed to manage a list of students with comprehensive CRUD operations. The application features user authentication, including registration and login, with secure password storage using hashing and JWT for maintaining authentication state. Additionally, it includes pagination and advanced search capabilities, allowing searches by name, country, age, email, gender, age range, etc.
The project uses a PostgreSQL database hosted on Supabase, managed through TypeORM. It adheres to RESTful API design principles, ensuring robust data validation and error handling. The application is thoroughly tested with unit tests for all services, controllers, and guards using Jest.
- Installation
- Environment Variables
- Running the Application
- Running Tests
- Project Structure
- Endpoints
- License
The application is deployed on Heroku. You can access the base URL here:
-
Clone the repository:
git clone https://github.com/yourusername/student-management-backend.git cd student-management-backend
-
Install dependencies:
npm install
Create a .env file in the root directory and add the following environment variables:
DB_HOST=your_database_host
DB_PORT=your_database_port
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
SECRET_KEY=your_jwt_secret_key
- Run the application:
npm run start
- Run the application in development mode:
npm run start:dev
- Run the application in production mode:
npm run start:prod
Run all tests:
npm run test
src/
|-- auth/
| |-- controllers/
| | |-- auth.controller.ts
| |-- services/
| | |-- auth.service.ts
| |-- auth.module.ts
|
|-- common/
| |-- dtos/
| | |-- registerUser.dto.ts
| | |-- signInUser.dto.ts
| |-- guards/
| | |-- auth.guard.ts
|
|-- database/
| |-- database.module.ts
|
|-- student/
| |-- controllers/
| | |-- student.controller.ts
| |-- dtos/
| | |-- createStudent.dto.ts
| | |-- student.dto.ts
| |-- entities/
| | |-- student.entity.ts
| |-- services/
| | |-- student.service.ts
| |-- student.module.ts
|
|-- user/
| |-- entities/
| | |-- user.entity.ts
| |-- services/
| | |-- user.service.ts
| |-- user.module.ts
|
|-- app.module.ts
-
POST /auth/login: User login
- Request Body:
{ "email": "[email protected]", "password": "password" }
- Response:
{ "access_token": "jwt_token" }
- Request Body:
-
POST /auth/register: User registration
- Request Body:
{ "email": "[email protected]", "password": "password", "confirmPassword": "password", "firstName": "First", "lastName": "Last" }
- Response:
{ "access_token": "jwt_token" }
- Request Body:
-
GET /students: Get all students
- Response:
[ { "id": 1, "firstName": "John", "lastName": "Doe", "email": "[email protected]", "birthDate": "1990-01-01", "gender": "Male", "country": "Country" }, ... ]
- Response:
-
POST /students: Add a new student
- Request Body:
{ "firstName": "John", "lastName": "Doe", "email": "[email protected]", "birthDate": "1990-01-01", "gender": "Male", "country": "Country" }
- Response:
{ "id": 1, "firstName": "John", "lastName": "Doe", "email": "[email protected]", "birthDate": "1990-01-01", "gender": "Male", "country": "Country" }
- Request Body:
-
PUT /students: Update an existing student
- Request Body:
{ "id": 1, "firstName": "John", "lastName": "Doe", "email": "[email protected]", "birthDate": "1990-01-01", "gender": "Male", "country": "Country" }
- Response:
{ "id": 1, "firstName": "John", "lastName": "Doe", "email": "[email protected]", "birthDate": "1990-01-01", "gender": "Male", "country": "Country" }
- Request Body:
-
DELETE /students/:id: Delete a student
- Response:
204 No Content
- Response:
-
GET /students/search: Search for students with pagination and filters
- Query Params:
page
,limit
,name
,country
,gender
,agefrom
,ageto
- Response:
{ "data": [...], "currentPage": 1, "totalPages": 10, "totalItems": 100 }
- Query Params:
This project is licensed under the MIT License. See the LICENSE file for details.