https://github.com/aksweb/algo8_task_management
A2: Task Management system with Node.js , MySQL and Jest Testing
https://github.com/aksweb/algo8_task_management
Last synced: 9 months ago
JSON representation
A2: Task Management system with Node.js , MySQL and Jest Testing
- Host: GitHub
- URL: https://github.com/aksweb/algo8_task_management
- Owner: aksweb
- Created: 2024-04-10T10:28:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-11T18:29:28.000Z (about 2 years ago)
- Last Synced: 2025-10-10T12:38:04.892Z (9 months ago)
- Language: JavaScript
- Homepage: https://algo8-task-management.onrender.com/tasks
- Size: 1.35 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# **Algo8 Task Management API Docs**
## This readme is divided into 3 sections
**A. Summary.**
**B. Steps & Requirements to run Hosted API.**
**C. Steps & Requirements to run Localhost API.**
## A. Summary
1. User creates the account by registering.
2. User Logs In and generates a JWT authentication token containing the userId.
3. Various CRUD operations like
a. Creating a Task.
b. Fetching user's task list.
c. Updating user's task.
d. Deleting user's task.
e. Deleting user and its related task.
4.**Hosting Server: Render ([Base Api: algo8-task-management.onrender.com](algo8-task-management.onrender.com))**
5.**Hosted MySQL Database : Clever-Cloud**
## _**B. Requirements for running the hosted API**_:
**1. Install POSTMAN or other REST API Testing tool**
**2. Internet Connection.**
## **APIs and how to access them:**
1. User Registration.
1. Do a POST request with the following JSON in the body.
```bash
POST https://algo8-task-management.onrender.com/signup
Content-Type: application/json
{
"email": "sonipuja@gmail.com",
"username": "sonipuja",
"password": "sonipuja123@"
}
```

2. User Login.
1. Do a POST request with the a similar type of JSON
2. After this you will receive a token.
3. Copy this token. This will be required for doing the CRUD operations.
```bash
POST https://algo8-task-management.onrender.com/login
Content-Type: application/json
{
"email": "soni@gmail.com",
"password": "soni"
}
```
Copy the generated token after login (you can find it in the response body).

```bash
token= "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsImVtYWlsIjoic29uaXB1amFAZ21haWwuY29tIiwiaWF0IjoxNzEyODM1Mjg4LCJleHAiOjE3MTI4Mzg4ODh9.Jj8X5Hx5ynjgXYtGNnSr1LjyYFZjtdPjrazKq7x8LHM"
```
CRUD APIs:
1. Create Task:API
1. Add Bearer Token as Authorization using the generated token.

2. Add the task as raw JSON in the body.

3. Do the POST request.
```bash
POST https://algo8-task-management.onrender.com/tasks
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsImVtYWlsIjoic29uaXB1amFAZ21haWwuY29tIiwiaWF0IjoxNzEyODM1Mjg4LCJleHAiOjE3MTI4Mzg4ODh9.Jj8X5Hx5ynjgXYtGNnSr1LjyYFZjtdPjrazKq7x8LHM
```
d. Observe the response:

2. Read Tasks API.
1. Add Bearer Token as Authorization using the generated token.

2. Do the GET request.
```bash
GET https://algo8-task-management.onrender.com/tasks
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsImVtYWlsIjoic29uaXB1amFAZ21haWwuY29tIiwiaWF0IjoxNzEyODM1Mjg4LCJleHAiOjE3MTI4Mzg4ODh9.Jj8X5Hx5ynjgXYtGNnSr1LjyYFZjtdPjrazKq7x8LHM
```
c. Observe the response in body.

3. Update Task API:
1. Add Bearer Token as Authorization using the generated token.

2. Add the updated task as raw JSON in the body.

3. Do the PUT request with the corresponding task ID.
```bash
PUT https://algo8-task-management.onrender.com/tasks/3
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsImVtYWlsIjoic29uaXB1amFAZ21haWwuY29tIiwiaWF0IjoxNzEyODM1Mjg4LCJleHAiOjE3MTI4Mzg4ODh9.Jj8X5Hx5ynjgXYtGNnSr1LjyYFZjtdPjrazKq7x8LHM
```
4. DELETE Task API:
1. Add Bearer Token as Authorization using the generated token.

2. Do the DELETE request with the corresponding task ID.
```bash
DELETE https://algo8-task-management.onrender.com/tasks/2
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsImVtYWlsIjoic29uaXB1amFAZ21haWwuY29tIiwiaWF0IjoxNzEyODM1Mjg4LCJleHAiOjE3MTI4Mzg4ODh9.Jj8X5Hx5ynjgXYtGNnSr1LjyYFZjtdPjrazKq7x8LHM
```
c. Observe the response.

5. DELETE USER API:
1. Add Bearer Token as Authorization using the generated token.

b.Do the DELETE request.
```bash
DELETE https://algo8-task-management.onrender.com/deluser
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsImVtYWlsIjoic29uaXB1amFAZ21haWwuY29tIiwiaWF0IjoxNzEyODM1Mjg4LCJleHAiOjE3MTI4Mzg4ODh9.Jj8X5Hx5ynjgXYtGNnSr1LjyYFZjtdPjrazKq7x8LHM
```
## _**C. Requirements for running the API on localhost**_:
**1. Clone this repository.**
```bash
git clone https://github.com/aksweb/algo8_Task_Management.git
```
**2. Install MySQL and Node.js.**
**3. Create a .env file containing the following variables as per your MySQL connection.**
```bash
DB_HOST
DB_USERNAME
DB_PASSWORD
DB_NAME
```
**4. Run the following SQL commands**
```bash
-- Database
CREATE DATABASE IF NOT EXISTS task_management_db;
-- Switch to db
USE task_management_db;
-- Create the users table
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(100) NOT NULL UNIQUE, username VARCHAR(50) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL
);
-- Create the tasks table
CREATE TABLE IF NOT EXISTS tasks (
id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100) NOT NULL, description TEXT, user_id INT, FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
);
```
**4. Open the project directory in terminal and run the following commands**
```bash
npm install
npm start
```
**6. Or To directly Test the APIs run the following command before stopping the server on port 3000:**
```bash
npm run test
```
**7. To manually test the API using REST api extension or POSTMAN as explained above, do the following:**
```bash
### signup
POST http://localhost:3000/signup
Content-Type: application/json
{
"email": "example@gmail.com",
"username": "exm",
"password": "exm"
}
### login
POST http://localhost:3000/login
Content-Type: application/json
{
"email": "example@gmail.com",
"password": "exm"
}
### get tasks of user
GET http://localhost:3000/tasks
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjU4LCJlbWFpbCI6InNvbmFsaUBnbWFpbC5jb20iLCJpYXQiOjE3MTI4MjQ2MDUsImV4cCI6MTcxMjgyODIwNX0.vxiYTsgjb7flM7q_bnGezrrq6puIZRq-sdV50-fqB_E
### creating tasks
POST http://localhost:3000/tasks
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjU4LCJlbWFpbCI6InNvbmFsaUBnbWFpbC5jb20iLCJpYXQiOjE3MTI4MjQ2MDUsImV4cCI6MTcxMjgyODIwNX0.vxiYTsgjb7flM7q_bnGezrrq6puIZRq-sdV50-fqB_E
{
"title": "mujhe gud paratha chaheye",
"description": "I m on diet"
}
###update
PUT http://localhost:3000/tasks/41
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjU4LCJlbWFpbCI6InNvbmFsaUBnbWFpbC5jb20iLCJpYXQiOjE3MTI4MjQ2MDUsImV4cCI6MTcxMjgyODIwNX0.vxiYTsgjb7flM7q_bnGezrrq6puIZRq-sdV50-fqB_E
{
"title": "testing",
"description": "I m on dietI m on diet"
}
### delete
DELETE http://localhost:3000/tasks/7
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjExLCJlbWFpbCI6InlhZGF2QGdtYWlsLmNvbSIsImlhdCI6MTcxMjc5NjkzNCwiZXhwIjoxNzEyODAwNTM0fQ.-7QHtq6E0u5KOsCsb-ghGeX0YmcVU63HWpYdoV9dZsA
### delete user and data
DELETE http://localhost:3000/deluser
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjExLCJlbWFpbCI6InlhZGF2QGdtYWlsLmNvbSIsImlhdCI6MTcxMjc5NjkzNCwiZXhwIjoxNzEyODAwNTM0fQ.-7QHtq6E0u5KOsCsb-ghGeX0YmcVU63HWpYdoV9dZsA
```
**Test Cases:**
1. Test case for the signup route
2. Test case for the login route.
3. Test case for the invalid login attempt.
4. Test case for fetching tasks.
5. Test case for unauthorized fetching.
6. Test case for creating a task.
7. Test case for updating a task.
8. Test case for deleting all tasks of the authenticated user.
