This API provides a set of features for managing tasks. Users can create tasks by specifying a title and description. Additionally, they have the ability to view a comprehensive list of all tasks, mark tasks as completed, edit task details, and delete tasks as needed. This API facilitates a flexible and efficient task management system, empowering users to organize and track their tasks seamlessly.
- Typescript
- Node.js
- Express.js
- MongoDB
- Jest
- Supertest
git clone git@github.com:vickatGit/ChainTechAssign.git
cd project-path
npm install
npm run dev
npm run jest:watch
- Validation is added to
email
andpassword
. Password should be a minimum of 8 characters, contain at least one capital and small letter, and include at least one number and one special character; otherwise, it throws an error.
const baseUrl = "http://localhost:8081/";
axios
.post(apiUrl, { email, userName, password })
.then((response) => {
console.log("β
Signup successful:", response.data);
})
.catch((error) => {
console.error("β Error during signup:", error.response.data);
});
- validation is added to
email
andpassword
and password should be minimum 8 characters and should at least one capital and small letter and number should be include and at least one special character is needed otherwise it throws the error
const baseUrl = "http://localhost:8080/";
axios
.post(`${baseUrl}auth/login`, { email, password })
.then((response) => {
console.log("π Login successful:", response.data);
})
.catch((error) => {
console.error("β Error during login:", error.response.data);
});
Get All Tasks
const baseUrl = "http://localhost:8081/";
axios
.get(`${baseUrl}tasks/tasks`)
.then((response) => {
console.log("π All tasks:", response.data);
})
.catch((error) => {
console.error("β Error fetching tasks:", error.response.data);
});
Get Tasks By Category
const baseUrl = "http://localhost:8080/";
const category = "Study";
axios
.get(`${baseUrl}tasks/tasks?category=${category}`)
.then((response) => {
console.log(`π Tasks with category ${category}:`, response.data);
})
.catch((error) => {
console.error(
`β Error fetching tasks by category ${category}:`,
error.response.data
);
});
Get Tasks By Status
const baseUrl = "http://localhost:8080/";
const status = "Completed";
axios
.get(`${baseUrl}tasks/tasks?status=${status}`)
.then((response) => {
console.log(`β
Completed tasks:`, response.data);
})
.catch((error) => {
console.error(`β Error fetching completed tasks:`, error.response.data);
});
Filter Tasks Based on Due Date
const baseUrl = "http://localhost:8080/";
const filterDate = "2024-01-26T20:11:00.678Z";
const isBefore = false;
axios
.get(`${baseUrl}tasks/tasks?filterDate=${filterDate}&isBefore=${isBefore}`)
.then((response) => {
const beforeOrAfter = isBefore ? "before" : "after";
console.log(`β° Tasks due ${beforeOrAfter} ${filterDate}:`, response.data);
})
.catch((error) => {
console.error(
`β Error fetching tasks based on due date:`,
error.response.data
);
});
Note
dueDate
should be after current timestatus
should only one of these [ βPending
β, βInProgress
β, βCompleted
β ]
const baseUrl = "http://localhost:8081/";
// Task data to be sent in the request body
const taskData = {
title: "Title 3",
description: "Title 3 Description",
status: "Pending",
dueDate: "2024-01-27T20:11:00.678Z",
};
// Make a POST request to create a new task
axios
.post(`${baseUrl}tasks/task`, taskData)
.then((response) => {
console.log("β
Task created successfully:", response.data);
})
.catch((error) => {
console.error("β Error creating task:", error.response.data);
});
Note
dueDate
should be after current timestatus
should only one of these [ βPending
β, βInProgress
β, βCompleted
β ]taskId
Should be Valid MongoDB Document id
const baseUrl = "http://localhost:8081/";
const taskId = "65b2775ddf91b52aef860d6a";
// Updated task data to be sent in the request body
const updatedTaskData = {
title: "Updated Title",
description: "Updated Description",
status: "Completed",
dueDate: "2024-01-28T15:30:00.000Z",
};
// Make a PATCH request to update the task
axios
.patch(`${baseUrl}tasks/task/${taskId}`, updatedTaskData)
.then((response) => {
console.log("β
Task updated successfully:", response.data);
})
.catch((error) => {
console.error("β Error updating task:", error.response.data);
});
Note
status
should only one of these [ βPending
β, βInProgress
β, βCompleted
β ]- if Task
status
is already completed then you can't modify the status of task, it throws the error
const baseUrl = "http://localhost:8081/";
const taskId = "65b2775ddf91b52aef860d6a";
// Updated task status data to be sent in the request body
const updatedTaskData = {
status: "In Progress",
};
// Make a PATCH request to update the task
axios
.patch(`${baseUrl}tasks/status/${taskId}`, updatedTaskData)
.then((response) => {
console.log("β
Task Status updated successfully:", response.data);
})
.catch((error) => {
console.error("β Error updating task status:", error.response.data);
});
Note
taskId
Should be Valid MongoDB Document id
const baseUrl = "http://localhost:8080/";
const taskId = "65b2c56d9f50ef32c5b37b48";
// Make a DELETE request to delete the task
axios
.delete(`${baseUrl}tasks/task/${taskId}`)
.then((response) => {
console.log("β
Task deleted successfully:", response.data);
})
.catch((error) => {
console.error("β Error deleting task:", error.response.data);
});
const baseUrl = "http://localhost:8080/";
// Make a GET request to fetch all task categories
axios
.get(`${baseUrl}tasks/categories`)
.then((response) => {
console.log("π Task categories:", response.data);
})
.catch((error) => {
console.error("β Error fetching task categories:", error.response.data);
});