Skip to content

SimonBrizuela/task-management-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Management API

A RESTful API for task management built with Node.js, Express, and MySQL. Features include user authentication, CRUD operations, task filtering, and comprehensive error handling.

Features

  • User authentication with JWT
  • Complete CRUD operations for tasks
  • Task filtering by status, priority, and date
  • Pagination and sorting
  • Input validation and error handling
  • MySQL database with proper relationships
  • API documentation with Swagger
  • Environment-based configuration

Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MySQL
  • Authentication: JWT (JSON Web Tokens)
  • Validation: express-validator
  • Documentation: Swagger/OpenAPI

Prerequisites

  • Node.js >= 14.x
  • MySQL >= 8.0
  • npm or yarn

Installation

# Clone the repository
git clone https://github.com/simonbrizuela/task-management-api.git
cd task-management-api

# Install dependencies
npm install

# Configure environment variables
cp .env.example .env
# Edit .env with your database credentials

# Run database migrations
npm run migrate

# Start the server
npm start

Environment Variables

PORT=3000
DB_HOST=localhost
DB_USER=your_user
DB_PASSWORD=your_password
DB_NAME=task_manager
JWT_SECRET=your_secret_key
JWT_EXPIRES_IN=24h
NODE_ENV=development

API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user
  • GET /api/auth/profile - Get user profile (protected)

Tasks

  • GET /api/tasks - Get all tasks (with filters)
  • GET /api/tasks/:id - Get task by ID
  • POST /api/tasks - Create new task
  • PUT /api/tasks/:id - Update task
  • DELETE /api/tasks/:id - Delete task
  • PATCH /api/tasks/:id/status - Update task status

Query Parameters

GET /api/tasks?status=pending&priority=high&page=1&limit=10&sort=createdAt&order=desc

Database Schema

Users
- id (PK)
- name
- email (unique)
- password (hashed)
- created_at

Tasks
- id (PK)
- user_id (FK)
- title
- description
- status (pending, in_progress, completed)
- priority (low, medium, high)
- due_date
- created_at
- updated_at

Usage Examples

Register User

curl -X POST http://localhost:3000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "john@example.com",
    "password": "securePassword123"
  }'

Create Task

curl -X POST http://localhost:3000/api/tasks \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{
    "title": "Complete API documentation",
    "description": "Write comprehensive API docs",
    "priority": "high",
    "due_date": "2024-12-31"
  }'

Project Structure

task-management-api/
├── src/
│   ├── config/
│   │   ├── database.js
│   │   └── swagger.js
│   ├── controllers/
│   │   ├── authController.js
│   │   └── taskController.js
│   ├── middleware/
│   │   ├── auth.js
│   │   ├── errorHandler.js
│   │   └── validator.js
│   ├── models/
│   │   ├── User.js
│   │   └── Task.js
│   ├── routes/
│   │   ├── auth.js
│   │   └── tasks.js
│   ├── utils/
│   │   ├── logger.js
│   │   └── helpers.js
│   └── app.js
├── migrations/
│   └── create_tables.sql
├── tests/
│   ├── auth.test.js
│   └── tasks.test.js
├── .env.example
├── .gitignore
├── package.json
└── README.md

Running Tests

npm test

API Documentation

Once the server is running, access the Swagger documentation at:

http://localhost:3000/api-docs

Security Features

  • Password hashing with bcrypt
  • JWT-based authentication
  • SQL injection prevention
  • Rate limiting
  • CORS configuration
  • Input validation and sanitization

License

MIT License - See LICENSE file for details

Author

Simon Brizuela

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors