A simple CRUD app using Nestjs
- User Registration and Login: Securely register and log in users with different roles (admin, manager, employee).
- Employee Management: Create, view, update, and delete employee details.
- Authentication & Authorization: Protect your API with JWT and control access based on user roles.
- Caching with Redis: Improve performance by caching frequent read operations.
(In progress)
- API Documentation with Swagger: Interactive and easy-to-use API docs for testing and development.
(In progress)
- NestJS: A progressive Node.js framework for building efficient and scalable server-side applications.
- MongoDB: A NoSQL database for storing employee data.
- Redis: An in-memory data store used for caching.
- Docker: Containerize the application for easy setup and deployment.
- Swagger: Auto-generate interactive API documentation.
-
Clone the Repository Open your terminal and run:
git clone https://github.com/1337fury/EmployeeMS-Nestjs.git
-
Navigate to the Project Directory
cd EmployeeMS-Nestjs
-
Set Up Environment Variables
Create a .env file in the root directory and add the following:
PORT=3000
MONGODB_URI=mongodb://mongo:27017/employee_db
JWT_SECRET=your_jwt_secret_key
REDIS_HOST=redis
REDIS_PORT=6379
-
Running the Application
docker-compose up --build
-
Access the Application
- API Endpoints: The application runs on http://localhost:3000.
- Swagger Documentation: Access the interactive API docs at http://localhost:3000/api. (In progress)
-
Register a New User
-
Endpoint:
POST /auth/register
-
Body:
{ "firstName": "fname", "lastName": "lname", "email": "[email protected]", "phoneNumber": "+2126....", "position": "Developer", "department": "Engineering", "password": "password123", "role": "admin" }
-
-
Log In
-
Endpoint:
POST /auth/login
-
Body:
{ "email": "[email protected]", "password": "password123" }
-
Response: You'll receive a JWT token to use for authenticated requests.
-
-
Manage Employees
- Create Employee:
POST /employees
- Get All Employees:
GET /employees
- Get Employee by ID:
GET /employees/{id}
- Update Employee:
PUT /employees/{id}
- Delete Employee:
DELETE /employees/{id}
- Create Employee:
Note: Use the JWT token in the
Authorization
header asBearer YOUR_TOKEN
to access protected routes.