Skip to content

Lekejosh/Task-Management-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Management API

Getting Started

These instructions will get a copy of the project up and running on your machine for development and testing purposes.

Prerequisites

To run this project locally, the following tools need to be installed:

Installation

Clone the project:

git clone https://github.com/Lekejosh/Task-Management-backend

Move into the project directory and install it's dependencies:

cd Task-Management-backend/
npm install

In the config folder create a file name "config.js"

Then paste and replace the below with your personal credentials

DB_URI = your db url here... example => 'mongodb://localhost:27017/taskManagement'

JWT_SECRET= Your JWT Secret here

JWT_EXPIRE = 5d

COOKIE_EXPIRE=5

PORT =4000 // Don't change this

SMPT_SERVICE=your service provider here... example=> gmail

SMPT_HOST= Host here... example=> stmp.gmail.com

SMPT_PORT=465

SMPT_MAIL=email address here

SMPT_PASSWORD=email password here

To start the dev API server run the following command:

npm run dev

Usage

Documentation

This is the documentaion of the api

link to the Postman version

REGISTER USER

/api/v1/register

For example:

POST:  http://localhost:4000/api/v1/register
Body
{
  "firstName": "Joshua",
  "lastName": "Adeleke",
  "password": "1234567890",
  "email": "[email protected]"
}
Response -400
{
  "success": false,
  "message": "User Already Exists"
}
Response - 201
{
  "success": true,
  "user": {
    "firstName": "Joshua",
    "lastName": "Adeleke",
    "email": "[email protected]",
    "password": "$2a$10$HnwC.Xksoa4kXUXDLNRA2OrI88RnkeOcxXP0Hm2uU4e1Qy/h02wmm",
    "role": "user",
    "_id": "638b1c0ff700c7f51a31745e",
    "created": "2022-12-03T09:51:11.288Z",
    "__v": 0
  },
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzOGIxYzBmZjcwMGM3ZjUxYTMxNzQ1ZSIsImlhdCI6MTY3MDA2MTA3MSwiZXhwIjoxNjcwNDkzMDcxfQ.VsTxLIyU1ACTusl888cYXY210qwM6GMkslv58EsMiIA"
}

LOGIN USER

/api/v1/login

For example:

POST:  http://localhost:4000/api/v1/login
Body
{
  "email": "[email protected]",
  "password": "1234567890"
}
Response - 401
{
  "success": false,
  "message": "Invalid email or Password"
}
Response -200
{
  "success": true,
  "user": {
    "_id": "638b1c0ff700c7f51a31745e",
    "firstName": "Joshua",
    "lastName": "Adeleke",
    "email": "[email protected]",
    "password": "$2a$10$HnwC.Xksoa4kXUXDLNRA2OrI88RnkeOcxXP0Hm2uU4e1Qy/h02wmm",
    "role": "user",
    "created": "2022-12-03T09:51:11.288Z",
    "__v": 0,
    "lastLoggedIn": "2022-12-03T09:52:44.895Z"
  },
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzOGIxYzBmZjcwMGM3ZjUxYTMxNzQ1ZSIsImlhdCI6MTY3MDA2MTE2NSwiZXhwIjoxNjcwNDkzMTY1fQ.foDVUc97sWPgt4gQhdGJDjVkaoA5FNMDGRjU_gCrXlY"
}

USER DETAILS

/api/v1/me

For example:

GET:  http://localhost:4000/api/v1/me
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response -200
{
  "success": true,
  "user": {
    "_id": "638b1c0ff700c7f51a31745e",
    "firstName": "Joshua",
    "lastName": "Adeleke",
    "email": "[email protected]",
    "role": "user",
    "created": "2022-12-03T09:51:11.288Z",
    "__v": 0,
    "lastLoggedIn": "2022-12-03T09:52:44.895Z"
  }
}

LOGOUT USER

/api/v1/logout

For example:

GET:  http://localhost:4000/api/v1/logout
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response --200
{
  "sucess": true,
  "Message": "logged out successfully"
}

FORGOT PASSWORD

/api/v1/password/forgot

For example:

POST:  http://localhost:4000/api/v1/password/forgot
Body
{
  "email": "[email protected]"
}
Respons - 404
{
  "success": false,
  "message": "User Not Found"
}

Response
{
  "success": true,
  "message": "Email sent to [email protected] successfully"
}

RESET PASSWORD

/api/v1/password/reset/:token

For example:

PUT:  http://localhost:4000/api/v1/password/reset/2f21043200b397ba7f4b1cce746aa9d184e85766
Body
{
  "password": "qwertyuiop",
  "confirmPassword": "qwertyuiop"
}
Response - 400
{
  "success": false,
  "message": "Reset Password Token is invalid or has expired"
}
Response - 200
{
  "success": true,
  "user": {
    "_id": "638b1c0ff700c7f51a31745e",
    "firstName": "Joshua",
    "lastName": "Adeleke",
    "email": "[email protected]",
    "role": "user",
    "created": "2022-12-03T09:51:11.288Z",
    "__v": 0,
    "lastLoggedIn": "2022-12-03T09:58:36.176Z",
    "password": "$2a$10$a5ZOP7tCww1YJFalSRRBLuqCUNgUcvFvlNTHW7pEA4jfGfo7z/uXq"
  },
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzOGIxYzBmZjcwMGM3ZjUxYTMxNzQ1ZSIsImlhdCI6MTY3MDA2MzAyNCwiZXhwIjoxNjcwNDk1MDI0fQ.LlhxLr3zcgddXgbTB50q0hJmq_tD-_aqobWkSOJn7Mw"
}

UPDATE PROFILE

/api/v1/profile/update

For example:

PUT:  http://localhost:4000/api/v1/profile/update
Body
{
  "firstName": "User",
  "lastName": "001",
  "email": "[email protected]"
}
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response -200
{
  "success": true,
  "user": {
    "_id": "638b1c0ff700c7f51a31745e",
    "firstName": "User",
    "lastName": "001",
    "email": "[email protected]",
    "role": "user",
    "created": "2022-12-03T09:51:11.288Z",
    "__v": 0,
    "lastLoggedIn": "2022-12-03T09:58:36.176Z"
  }
}

ALL USERS -- ADMIN

/api/v1/users

For example:

GET:  http://localhost:4000/api/v1/admin/users
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 403
{
  "success": false,
  "message": "Role: user is not allowed to access this resource"
}
Response - 200
{
  "success": true,
  "users": [
    {
      "_id": "638a96ce5bf6fb242c9e845c",
      "firstName": "hua",
      "lastName": "leke",
      "email": "[email protected]",
      "role": "admin",
      "created": "2022-12-03T00:22:38.290Z",
      "__v": 0,
      "lastLoggedIn": "2022-12-03T10:29:41.838Z"
    },
    {
      "_id": "638b1c0ff700c7f51a31745e",
      "firstName": "User",
      "lastName": "001",
      "email": "[email protected]",
      "role": "user",
      "created": "2022-12-03T09:51:11.288Z",
      "__v": 0,
      "lastLoggedIn": "2022-12-03T09:58:36.176Z"
    }
  ]
}

SINGLE USER -- ADMIN

/api/v1/admin/user/:id

For example:

GET:  http://localhost:4000/api/v1/admin/user/638b1c0ff700c7f51a31745e
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 403
{
  "success": false,
  "message": "Role: user is not allowed to access this resource"
}
Response - 200
{
  "success": true,
  "user": {
    "_id": "638b1c0ff700c7f51a31745e",
    "firstName": "User",
    "lastName": "001",
    "email": "[email protected]",
    "role": "user",
    "created": "2022-12-03T09:51:11.288Z",
    "__v": 0,
    "lastLoggedIn": "2022-12-03T09:58:36.176Z"
  }
}

UPDATE USER -- ADMIN

/api/v1/admin/user/:id

For example:

PUT:  localhost:4000/api/v1/admin/user/638b1c0ff700c7f51a31745e
body
{
  "firstName": "User",
  "email": "[email protected]",
  "role": "user"
}
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 403
{
  "success": false,
  "message": "Role: user is not allowed to access this resource"
}
Response - 200
{
  "success": true,
  "message": "User Updated Successfully"
}

DELETE USER -- ADMIN

/api/v1/admin/user/:id

For example:

DELETE:  localhost:4000/api/v1/admin/user/638b1c0ff700c7f51a31745e
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 403
{
  "success": false,
  "message": "Role: user is not allowed to access this resource"
}
Response - 200
{
  "success": true,
  "message": "User Deleted Successfully"
}

CREATE TASK

/api/v1/task/create

For example:

POST:  http://localhost:4000/api/v1/task/create
Body
{
  "date": "01-02-2001",
  "prority": "Very Important",
  "description": "Some Urgent"
}
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 200
{
  "success": true,
  "task": {
    "date": "2001-01-01T23:00:00.000Z",
    "prority": "Very Important",
    "description": "Some Urgent",
    "completed": false,
    "user": "638a96ce5bf6fb242c9e845c",
    "_id": "638b28c95efe287e61939835",
    "__v": 0
  }
}

GET USER TASKS

/api/v1/task/me

For example:

GET:  http://localhost:4000/api/v1/task/me
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 200
{
  "success": true,
  "task": [
    {
      "_id": "638b28c95efe287e61939835",
      "date": "2001-01-01T23:00:00.000Z",
      "prority": "Very Important",
      "description": "Some Urgent",
      "completed": false,
      "user": "638a96ce5bf6fb242c9e845c",
      "__v": 0
    },
    {
      "_id": "638b28f45efe287e6193983a",
      "date": "2022-01-01T23:00:00.000Z",
      "prority": "Very Important",
      "description": " Urgent",
      "completed": false,
      "user": "638a96ce5bf6fb242c9e845c",
      "__v": 0
    }
  ]
}

GET SINGLE TASK

/api/v1/task/:id

For example:

GET:  localhost:4000/api/v1/task/638b35ce12d58800695c5b48
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 200
{
    "success": true,
    "task": {
        "_id": "638b35ce12d58800695c5b48",
        "date": "2022-01-02T23:00:00.000Z",
        "prority": "Very Important",
        "description": "Some Urgent",
        "completed": true,
        "user": "638b1c0ff700c7f51a31745e",
        "__v": 0
    }
}

GET COMPLETED TASK

/api/v1/task/user/completed

For example:

GET:  localhost:4000/api/v1/task/user/completed
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 200
{
    "success": true,
    "task": {
        "_id": "638b35ce12d58800695c5b48",
        "date": "2022-01-02T23:00:00.000Z",
        "prority": "Very Important",
        "description": "Some Urgent",
        "completed": true,
        "user": "638b1c0ff700c7f51a31745e",
        "__v": 0
    }
}

GET TASK BY DATE

/api/v1/task/user/date?q=YYYY-MM-DD

For example:

GET:  localhost:4000/api/v1/task/user/date?q=2022-01-02
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 200
{
    "success": true,
    "task": {
        "_id": "638b35ce12d58800695c5b48",
        "date": "2022-01-02T23:00:00.000Z",
        "prority": "Very Important",
        "description": "Some Urgent",
        "completed": true,
        "user": "638b1c0ff700c7f51a31745e",
        "__v": 0
    }
}

UPDATE TASKS

/api/v1/task/:id/update

For example:

PUT:  localhost:4000/api/v1/task/638b28c95efe287e61939835/update
body
{
  "date": "01-03-2022",
  "prority": "Very Important",
  "description": "Some Urgent",
  "completed": true
}
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 200
{
  "success": true,
  "task": {
    "_id": "638b28c95efe287e61939835",
    "date": "2022-01-02T23:00:00.000Z",
    "prority": "Very Important",
    "description": "Some Urgent",
    "completed": true,
    "user": "638a96ce5bf6fb242c9e845c",
    "__v": 0
  }
}

DELETE TASKS

/api/v1/task/:id

For example:

DELETE:  localhost:4000/api/v1/task/638b28c95efe287e61939835
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 200
{
    "success": true,
    "message": "Task Delete successfully"
}

DELETE ALL TASKS

/api/v1/task/delete/all

For example:

DELETE:  localhost:4000/api/v1/task/delete/all
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 200
{
    "success": true,
    "message": "Task Delete successfully"
}

DELETE ALL COMPLETED TASKS

/api/v1/task/delete/completed

For example:

DELETE:  localhost:4000/api/v1/task/delete/completed
Response - 401
{
  "success": false,
  "message": "Please Login to access this resource"
}
Response - 200
{
    "success": true,
    "message": "Task Delete successfully"
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published