Skip to content

vzorr/UstaDashboardBackend

Repository files navigation

Usta Dashboard Backend

A Node.js backend API server for the Usta Dashboard application, built with Express.js and MongoDB.

Features

  • Express.js server with middleware setup
  • MongoDB integration with Mongoose
  • CORS configuration
  • Security headers with Helmet
  • Request logging with Morgan
  • Environment configuration
  • Error handling
  • Health check endpoints
  • Ticket Management System with CRUD operations
  • File upload support with Multer
  • Multiple image attachments support

Prerequisites

  • Node.js (v14 or higher)
  • MongoDB (running locally or MongoDB Atlas)
  • npm or yarn

Installation

  1. Clone the repository

  2. Install dependencies:

    npm install
  3. Create a .env file based on config.env:

    cp config.env .env
  4. Update the .env file with your MongoDB connection string and other configurations.

Configuration

The application uses environment variables for configuration. Key variables include:

  • PORT: Server port (default: 3000)
  • NODE_ENV: Environment (development/production)
  • MONGODB_URI: MongoDB connection string
  • JWT_SECRET: Secret key for JWT tokens (if using authentication)
  • CORS_ORIGIN: Allowed CORS origins

Running the Application

Development Mode

npm run dev

Production Mode

npm start

API Endpoints

General Endpoints

  • GET / - Welcome message and API information
  • GET /health - Health check endpoint
  • GET /api - API routes information

Ticket Management Endpoints

Create Ticket

POST /api/tickets
Content-Type: multipart/form-data

Fields:
- category (required): String
- description (required): String
- relatedJob (optional): String (job ID)
- submittedBy (required): String (user ID)
- attachments (optional): File[] (multiple files)

Get All Tickets

GET /api/tickets?page=1&limit=10&status=open&category=bug&submittedBy=userId&sortBy=createdAt&sortOrder=desc

Get Ticket by ID

GET /api/tickets/:id

Update Ticket

PUT /api/tickets/:id
Content-Type: multipart/form-data

Fields:
- category: String
- description: String
- relatedJob: String
- status: String (open, in-progress, resolved, closed)
- priority: String (low, medium, high, urgent)
- assignedTo: String
- attachments: File[] (new files will replace existing ones, or use "append" to add)

Delete Ticket

DELETE /api/tickets/:id

Add Comment to Ticket

POST /api/tickets/:id/comments
Content-Type: application/json

{
  "user": "userId",
  "comment": "Comment text"
}

Get Tickets by User

GET /api/tickets/user/:userId?page=1&limit=10

Ticket Data Structure

interface CreateTicketData {
  category: string; // Required
  description: string; // Required
  relatedJob?: string; // Optional job ID
  attachments: File[]; // Multiple files supported
  submittedBy: string; // Required user ID
}

File Upload Support

  • Supported file types: Images (jpg, png, gif, webp), PDF, Word docs, text files
  • File size limit: 10MB per file
  • Maximum files: 5 files per request
  • Upload directory: uploads/tickets/
  • Static file serving: Files accessible at /uploads/tickets/filename

Project Structure

UstaDashboardBackend/
├── config/
│   ├── database.js          # MongoDB connection configuration
│   └── multer.js           # File upload configuration
├── controllers/
│   └── ticketController.js  # Ticket CRUD operations
├── models/
│   └── Ticket.js           # Ticket Mongoose model
├── routes/
│   └── ticketRoutes.js     # Ticket API routes
├── uploads/
│   └── tickets/           # Uploaded files directory
├── server.js              # Main server file
├── package.json           # Project dependencies and scripts
├── config.env            # Environment variables template
├── .gitignore           # Git ignore rules
└── README.md            # Project documentation

Example Usage

Creating a Ticket with Files

curl -X POST http://localhost:3000/api/tickets \
  -F "category=bug" \
  -F "description=Application crashes on login" \
  -F "submittedBy=user123" \
  -F "relatedJob=job456" \
  -F "attachments=@/path/to/screenshot1.png" \
  -F "attachments=@/path/to/logfile.txt"

Getting All Tickets

curl "http://localhost:3000/api/tickets?page=1&limit=5&status=open"

Adding a Comment

curl -X POST http://localhost:3000/api/tickets/ticketId/comments \
  -H "Content-Type: application/json" \
  -d '{"user": "user123", "comment": "This issue has been reproduced"}'

Development

The project uses nodemon for development, which automatically restarts the server when files change.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test your changes
  5. Submit a pull request

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published