/task-tracker-api

Primary LanguageTypeScriptApache License 2.0Apache-2.0

Task Tracker API

A TypeScript Node.js API project for managing tasks with a PostgreSQL database.

You can find a live demo version of this project deployed using Render here - https://task-tracker-api-2z5y.onrender.com/

In the live demo version, We are using a PostgreSQL database deployed on AWS RDS.

Note - Server may go down occasionally due to inactivity as it's on free tier

Table of Contents

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js and npm installed.
  • PostgreSQL database server running.

Getting Started

Installing Dependencies

  1. Clone this repository to your local machine:

    git clone https://github.com/yourusername/task-tracker-api.git
  2. Navigate to the project directory:

    cd task-tracker-api
  3. Install project dependencies:

    npm install

Setting Up the Database

  1. Create a PostgreSQL database for the project.

  2. Copy the below .env file contents to your .env and configure the database connection details:

    DATABASE_NAME=yourdbname
    DATABASE_USERNAME=yourdbusername
    DATABASE_PASSWORD=yourdbpassword
    DATABASE_HOST=yourdatabasehost
    DATABASE_PORT=5432

Running Migrations

To create the necessary database tables, run the following migration command:

npm run migrate

You will see the following message upon successful migration

Connected to the database
Migration completed successfully
Disconnected from the database

Starting the Server

Start the Node.js server:

npm run dev

By default, the server will run on http://localhost:3000.

API Endpoints

  • GET /: Check app status
    • Response Example:
      { "message":"App is running on port 3000" }

Task Endpoints

  • POST /api/tasks: Create a new task.

    • Request Body:
      {
        "title": "Task Title",
        "description": "Task Description",
        "status": "open"
      }
    • Response Example:
      {
        "status": "success",
        "data": {
          "id": 1,
          "title": "Task Title",
          "description": "Task Description",
          "status": "open",
          "createdAt": "2023-09-28T12:00:00Z",
          "updatedAt": "2023-09-28T12:00:00Z"
        }
      }
  • PUT /api/tasks/{taskId}: Update a task's status.

    • Request Params:
      • taskId (integer): ID of the task to update.
    • Request Body:
      {
        "status": "inprogress"
      }
    • Response Example:
      {
        "status": "success",
        "data": {
          "id": 1,
          "title": "Task Title",
          "description": "Task Description",
          "status": "inprogress",
          "createdAt": "2023-09-28T12:00:00Z",
          "updatedAt": "2023-09-28T14:00:00Z"
        }
      }
  • GET /api/tasks: Get all tasks with pagination.

    • Query Params:
      • page (integer, optional): Page number (default: 1).
      • limit (integer, optional): Number of tasks per page (default: 10).
    • Request Example - /api/tasks?page=1&limit=8
    • Response Example:
      {
        "status": "success",
        "data": {
          "totalTasks": 2,
          "currentPage": 1,
          "tasks": [
            {
              "id": 1,
              "title": "Task 1",
              "description": "Description 1",
              "status": "open",
              "createdAt": "2023-09-28T12:00:00Z",
              "updatedAt": "2023-09-28T12:00:00Z"
            },
            {
              "id": 2,
              "title": "Task 2",
              "description": "Description 2",
              "status": "completed",
              "createdAt": "2023-09-28T13:00:00Z",
              "updatedAt": "2023-09-28T13:00:00Z"
            }
          ]
        }
      }

Metrics Endpoints

  • GET /api/metrics: Get all task metrics (ungrouped).

    • Response Example:
      {
        "status": "success",
        "data": {
          "totalTasks": 50,
          "openTasks": 20,
          "inprogressTasks": 15,
          "completedTasks": 15
        }
      }
  • GET /api/metrics/{month}: Get task metrics for a specific month.

    • Request Params:
      • month (string): Month in 'YYYY-MM' format.
    • Response Example:
      {
        "status": "success",
        "data": {
          "month": "October 2023",
          "metrics": {
            "totalTasks": "1",
            "openTasks": "0",
            "inprogressTasks": "0",
            "completedTasks": "1"
          }
        }
      }
  • GET /api/metrics/grouped: Get task metrics grouped by month.

    • Response Example:
      {
        "status": "success",
        "data": [
          {
            "month": "September 2023",
            "metrics": {
              "totalTasks": "2",
              "openTasks": "1",
              "inprogressTasks": "1",
              "completedTasks": "0"
            }
          },
          {
            "month": "October 2023",
            "metrics": {
              "totalTasks": "1",
              "openTasks": "0",
              "inprogressTasks": "0",
              "completedTasks": "1"
            }
          }
        ]
      }

For more API details of endpoints and documentation, please refer to the Swagger Documentation section below.

Swagger Documentation

You can access the Swagger documentation to explore and test the API endpoints: