Skip to content

hverma73/userDocuManagement

Repository files navigation

NestJS User Management & Document Management API

Overview

This project is a NestJS backend service for user authentication, user management, document management, and ingestion controls. It includes role-based access control (RBAC) and integrates PostgreSQL as the database.

Features

  • Authentication: User registration, login, logout, JWT-based authentication.
  • User Management: CRUD operations for users with role-based permissions.
  • Document Management: Upload, fetch, update, and delete documents.
  • Ingestion API: Trigger ingestion process and track ongoing ingestion tasks.
  • Microservices Architecture: Scalable and modular design.

Tech Stack

  • NestJS (Node.js framework)
  • TypeScript
  • PostgreSQL with TypeORM
  • JWT Authentication
  • bcrypt (Password hashing)
  • Swagger (API documentation)

Installation & Setup

Prerequisites

Ensure you have the following installed:

  • Node.js (v16+)
  • PostgreSQL

Clone the Repository

git clone https://github.com/your-repo.git
cd your-repo

Install Dependencies

npm install

Set Up Environment Variables

Create a .env file and configure the necessary variables:

DATABASE_URL=postgres://user:password@localhost:5432/mydatabase
JWT_SECRET=your_jwt_secret
PORT=3000

Run the Application

npm run start:dev

API Documentation

Authentication APIs

Register User

POST /auth/register

{
  "email": "[email protected]",
  "password": "password123",
  "role": "viewer"
}

Response:

{
  "id": 1,
  "email": "[email protected]",
  "role": "viewer"
}

Login

POST /auth/login

{
  "email": "[email protected]",
  "password": "password123"
}

Response:

{
  "access_token": "jwt_token_here"
}

Logout

POST /auth/logout Response:

{
  "message": "Logout successful"
}

User Management APIs (Admin Only)

Get All Users

GET /users Response:

[
  { "id": 1, "email": "[email protected]", "role": "admin" },
  { "id": 2, "email": "[email protected]", "role": "editor" }
]

Update User Role

PATCH /users/:id/role

{
  "role": "admin"
}

Response:

{
  "id": 2,
  "email": "[email protected]",
  "role": "admin"
}

Delete User

DELETE /users/:id Response:

{
  "message": "User deleted successfully"
}

Document Management APIs

Upload Document

POST /documents/upload Headers: Authorization: Bearer <JWT>

Form-Data:

  • file: Upload a document file.

Response:

{
  "id": 1,
  "filename": "document.pdf",
  "uploadedBy": "[email protected]"
}

Get All Documents

GET /documents Response:

[
  { "id": 1, "filename": "doc1.pdf", "uploadedBy": "[email protected]" },
  { "id": 2, "filename": "doc2.docx", "uploadedBy": "[email protected]" }
]

Delete Document

DELETE /documents/:id Response:

{
  "message": "Document deleted successfully"
}

Ingestion APIs

Trigger Ingestion Process

POST /ingestion/trigger

{
  "documentId": 1
}

Response:

{
  "message": "Ingestion process started for documentId 1"
}

Get Ingestion Status

GET /ingestion/status/:id Response:

{
  "documentId": 1,
  "status": "Processing"
}

Running Tests

To run unit tests:

npm run test

To run integration tests:

npm run test:e2e

Deployment

To build the project:

npm run build

To start in production mode:

npm run start:prod

Contributors

  • Harsh Verma - Developer

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published