A RESTful API for managing tasks, built with Node.js, Express, and PostgreSQL.
- JWT-based authentication
- CRUD operations for tasks
- Task status tracking
- Time tracking
- Task reporting
- Input validation
- Error handling
- Pagination and filtering
- Node.js
- Express.js
- PostgreSQL
- Sequelize ORM
- TypeScript
- JWT for authentication
- Zod for validation
- bcrypt for password hashing
- Node.js (v14 or higher)
- PostgreSQL
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd task-management- Install dependencies:
npm install- Create a
.envfile in the root directory with the following variables:
NODE_ENV=development
PORT=3001
JWT_SECRET=your-super-secret-jwt-key-change-in-production
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/task_management
ADMIN_SECRET=your-desire-secret-id
- Create the database:
createdb task_management- Start the server:
npm run buildnpm run dev
```
5. Run migrations:
```bash
npm run migrate
```
## API Endpoints
### Authentication
- POST /api/users/signup - Signup a new user
Admin and the regular users uses one endpoint to signup
User:
{
"firstName":
"lastName":
"email" :
"password":
}
Admin
{
"firstName":
"lastName":
"email" :
"password":
"adminSecret" :your secret key inside the env
}
- POST /api/users/login - Login user
### Admin fetchall users
```
- GET /api/admin/users - Admin fetch all users
### Tasks
- POST /api/tasks - Create a new task
- GET /api/tasks - List all tasks (with pagination and filtering)
- PATCH /api/tasks/:id - Update a task
- DELETE /api/tasks/:id - Delete a task
- GET /api/tasks/report - Get task completion report
- GET /api/tasks/report-time - Get task completion report
## API Usage Examples
### Create a Task
```bash
curl -X POST http://localhost:3001/api/tasks \
-H "Authorization: Bearer <your-token>" \
-H "Content-Type: application/json" \
-d '{
"title": "Complete project",
"description": "Finish the task management API",
"priority": "HIGH",
"dueDate": "2024-03-20T00:00:00Z"
}'curl -X GET "http://localhost:3001/api/tasks?page=1&limit=10&status=IN_PROGRESS" \
-H "Authorization: Bearer <your-token>"curl -X PUT http://localhost:3001/api/tasks/<task-id> \
-H "Authorization: Bearer <your-token>" \
-H "Content-Type: application/json" \
-d '{
"status": "COMPLETED",
"timeSpent": 120
}'The API uses a centralized error handling system that returns errors in the following format:
{
"success": false,
"message": "Error message",
"data": null
}- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.