This is a simple todo app using Express and MongoDB. Home page
- A user can view the task she/he planned to do in the order of the priority from highest to lowest.
- A user can add any number of tasks and assign a priority for it.
- A task can be marked as completed or incomplete and also can be cancelled.
- A task can also be deleted from the listing which also removes it from the database. The web page showing tasks can be viewed here , but token has to be supplied as a query parameter 'token'.
- A user can generate a short report where pending,completed and cancelled tasks are displayed in the order of priority.
- Count of pending, completed, cancelled and deleted tasks are also displayed. The web page showing report can be viewed here , but token has to be supplied as a query parameter 'token'.
- Backend: NodeJS
- Framework: ExpressJS
- Database: MongoDB
- Frontend: JS, HTML (PUG), CSS
-
Clone this repository.
git clone https://github.com/Jarosh-Antony/todoapp
-
Navigate to
todoapp
.cd todoapp
-
Initialise the nodeJS project repository and install necessary packages.
npm init npm install
-
Create a .env file to store hostname, MongoDB URL and Secret key for token generation in the current directory.
HOSTNAME=[HOSTNAME] DB=[MONGODB URL] SECRET_KEY=[SECRET KEY FOR TOKENS]
-
Run the app.
npm start
The app automatically create a database with name todo
. It also automatically creates collections Tasks
and Users
. 'Users' store the details of users for authentication. 'Tasks' store the details of each tasks of every users along with its priority and current status.
Status can be Completed
, Incomplete
and Cancelled
.
-
-
An endpoint to autherize a user.
POST /auth/api/login 'Content-Type': 'application/json' { "email" : "john@j.com", "password" : "abcdefgh" }
HTTP 200 OK { "token" : "sdfefefsd.sdfsdsdfsd.dfsdfsdf" }
-
An endpoint to create a new user with given details.
POST /auth/api/signup 'Content-Type': 'application/json' { "name" : "John", "email" : "john@j.com", "password" : "abcdefgh" }
HTTP 201 OK { "token" : "regrtg.bcdfdg.xcvvdfgd" }
-
-
-
An endpoint to get the tasks.
GET /todo/tasks 'Authorization': 'Bearer [TOKEN]'
HTTP 200 OK { "tasks": [ { "_id" : "63dac56e3eed5f9669391a27", "name" : "Take out garbage", "priority" : 2, "id" : "63d7f4d1d7be2090d9e94de5", "status" : "Cancelled" } { "_id" : "63df5f868284d5e1b494e532", "name" : "Pay electricity bill", "priority" : 1, "id" : "63df5f498284d5e1b494e52f", "status" : "Incomplete" } { "_id" : "63df8d4b314f4dfa02057858", "name" : "Buy gifts", "priority" : 5, "id" : "63d7f4d1d7be2090d9e94de5", "status" : "Cancelled" } ] }
_id
is the task id.id
is the user id of the user to whom the task belongs to.- Since request query doesn't have
name
,priority
, andstatus
, complete data belonging to the user is returned. - Since request query doesn't have
sort
, the data is sorted in the order of_id
. - Since request query doesn't have
order
, the data is ordered in ascending order. - If
order
is present withoutsort
, thenorder
will be tried to be matched with fields in data. This will result in response being empty since there is no field namedorder
.
GET /todo/tasks?status=Cancelled&sort=priority&order=DESC 'Authorization': 'Bearer [TOKEN]'
HTTP 200 OK { "tasks": [ { "_id" : "63df8d4b314f4dfa02057858", "name" : "Buy gifts", "priority" : 5, "id" : "63d7f4d1d7be2090d9e94de5", "status" : "Cancelled" } { "_id" : "63dac56e3eed5f9669391a27", "name" : "Take out garbage", "priority" : 2, "id" : "63d7f4d1d7be2090d9e94de5", "status" : "Cancelled" } ] }
- Request query accepts
name
,priority
,status
and any combination of them. - Request query also accepts
sort
which sorts data based on the values in field represented by value ofsort
. - Sort order can be
DESC
for descending order andASC
for ascending order. - If
order
is invalid, the data will be sorted in ascending order. - If
sort
is invalid, then the data will be sorted based on_id
.
-
An endpoint to create a task with given information.
POST /todo/tasks/create 'Content-Type': 'application/json', 'Authorization': 'Bearer [TOKEN]' { "name" : "Recharge mobile", "priority" : 8 }
HTTP 201 OK
-
An endpoint to update the
status
of a task.PUT /todo/tasks/update 'Content-Type': 'application/json', 'Authorization': 'Bearer [TOKEN]' { "_id" : "1231238374872389379", "status" : "Completed", }
_id
is the task id.status
can beCompleted
,Incomplete
andCancelled
.
HTTP 204 OK
-
An endpoint to delete a task from database.
DELETE /todo/tasks/delete 'Content-Type': 'application/json', 'Authorization': 'Bearer [TOKEN]' { "_id" : "593t86045094305943509409" }
_id
is the task id.
HTTP 204 OK
-
-
-
An endpoint to get the counts of tasks grouped by their
status
.GET /report/count 'Authorization': 'Bearer [TOKEN]'
HTTP 200 OK { "count" : { "Cancelled" : 6, "Completed" : 1, "Deleted" : 27, "Incomplete": 0 } }
GET /report/count?Status=Deleted 'Authorization': 'Bearer [TOKEN]'
HTTP 200 OK { "count" : 27 }
- Instead of
Deleted
one can useCompleted
,Incomplete
andCancelled
. - Only accepted request query is
Status
. - Trying out different query produces same response as request without any query.
- Trying out different values for query produces
0
forcount
.
- Instead of
-
-
- No token or invalid token when required.
HTTP 401 Unauthorized
- Internal Server Error.
HTTP 500 Internal Server Error
- Invalid/empty values when updating.
HTTP 400 Bad Request