This documentation provides an overview of the project structure, API endpoints, database models, and instructions for setting up and testing the project. The project is built using Node.js, Express.js, and MongoDB.
- Project Overview
- Setup Instructions
- API Endpoints
- Database Models
- Authentication
- Error Handling
- Cron Jobs
- Testing
- Postman Collection
The project involves creating APIs for task management, including tasks, subtasks, and cron jobs for task priority and Twilio voice calling. It also emphasizes proper validation, error handling, and user authentication using JWT.
-
Fork the repository to your GitHub account.
-
Clone the forked repository to your local machine
git clone https://github.com/your-username/Backend-Engineer-Assignment.git
cd Backend-Engineer-Assignment -
Create a MongoDB database and obtain your MongoDB URI from MongoDB Atlas.
-
Create a Twilio account and obtain your Account Sid,Auth Token & Phone Number from Twilio.
-
Rename the
.env.examplefile to.envand add the following environment variables:.NODE_ENV=development PORT=5000 JWT_SECRET=YOUR_JWT_SECRET MONGO_URI=YOUR_MONGO_URI TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID TWILIO_AUTH_TOKEN=YOUR_TWILIO_AUTH_TOKEN TWILIO_PHONE_NUMBER=YOUR_TWILIO_PHONE_NUMBER -
Install dependencies.
npm install
-
Run the application.
npm start
or
npm run dev
-
The application should now be running on
http://localhost:5000.
- Endpoint:
POST /api/v1/tasks - Input:
title(string)description(string)dueDate(date)
- Authorization: JWT token required
- Endpoint:
POST /api/v1/sub-tasks/:id - Input:
taskId(Number)
- Authorization: JWT token required
- Endpoint:
GET /api/v1/tasks - Query Parameters:
priority(Number, optional)dueDate(date, optional)page(Number, optional)limit(Number, optional)
- Authorization: JWT token required
- Endpoint:
GET /api/v1/sub-tasks/:id - Path Parameters:
taskId(Number)
- Query Parameters:
taskId(Number, optional)
- Authorization: JWT token required
- Endpoint:
PUT /api/v1/tasks/:id - Input:
due_date(date, optional)status("TODO" or "DONE", optional)
- Authorization: JWT token required
- Endpoint:
PUT /api/v1/sub-tasks/:id - Input:
status(0 or 1)
- Authorization: JWT token required
- Endpoint:
PATCH /api/v1/tasks/:id - Authorization: JWT token required
- Endpoint:
PATCH /api/v1/sub-tasks/:id - Authorization: JWT token required
{
_id: ObjectId, // Generate by MongoDB
title: String,
description: String,
dueDate: Date,
priority: Number,
status: String,
subtasks: Array // Subtask schema
createdAt: Date,
updatedAt: Date,
deletedAt: Date // Soft deletion field
}{
_id: ObjectId, // Generate by MongoDB
taskId: ObjectId, // Reference to Task Model
status: Number,
createdAt: Date,
updatedAt: Date,
deletedAt: Date
}{
_id: ObjectId, // Generate by MongoDB
phoneNumber: Number,
priority: Number
}JWT (JSON Web Token) is used for user authentication.
Proper validation is implemented for input parameters. User-friendly error messages are returned for invalid requests. Additionally, common HTTP error status codes are used for different scenarios.
- Logic: Priorities are assigned based on the due date of tasks.
- Priority 0: Due date is today.
- Priority 1: Due date is between tomorrow and the day after tomorrow.
- Priority 2: Due date is 3-4 days from today.
- Priority 3: Due date is 5 days or more from today.
- Logic: Twilio voice calls are triggered if a task passes its due date. Calling priority is determined by the user's priority.
- Users with priority 0 are called first, followed by priority 1, and then priority 2.
- A user is called only if the previous user does not attend the call.
Postman can be used to test all the APIs. Ensure that proper authentication tokens are included in the requests. Test cases should cover various scenarios, including valid and invalid inputs, error handling, and the proper functioning of cron jobs.
A Postman collection is provided in the repository (Tasks Management.postman_collection.json). Import this collection into Postman for easy testing of the APIs.