This is the backend component for the Pomodoro-React web application. It's built with Node.js, Express, and MongoDB, Passport.js, and provides the API endpoints that the frontend interacts with.
-
Clone this repository and cd into the project directory.
-
Install dependencies with npm install.
-
Create a .env file in the root directory with the following variables:
PORT='port-number' URI= 'mongo-db-uri' PRIV= 'private key (RSA)' PUB= 'public key (RSA)'
Replace 'port-number' with the desired port number for the server to run on, 'mongo-db-uri' with the URI for your MongoDB database, and PRIV and PUB with RSA keys of your choosing to sign JSON web tokens.
-
Start the server with npm start.
Registers a new user.
Request body (Form or URL Params):
{
"username": "username",
"password": "password"
}
Returns a JSON object containing a success or failure message:
{
"message": "successfully registered",
}
Logs a user in and returns a JSON web token.
Request body (Form or URL Params):
{
"username": "username",
"password": "password"
}
Returns a JSON object containing the JWT:
{
"success": BOOLEAN,
"token": STRING(JSON Web Token),
"expiresIn": DATE
}
Requires JWT Authorization in header:
Bearer: "Authorization STRING(JSON Web Token)"
Gets a summary of a user.
Returns a JSON object containing the user's summary:
{
"projects": [
{
"id": INTEGER,
"title": STRING,
"user": MONGOID,
"description": STRING,
"start_date": DATE,
"end_date": DATE
}
],
"tasks": [
{
"id": MONGOID,
"project": MONGOID,
"user": MONGOID,
"title": STRING,
"created": DATE,
"completed": BOOLEAN,
"timeSpent": INTEGER,
"estimatedTime": INTEGER,
}
],
"logs": [
{
"_id": MONGOID,
"task": MONGOID,
"user": MONGOID,
"completed": BOOLEAN,
"duration": INTEGER,
"startTime": DATE,
}
]
}
Gets a list of all projects.
Returns a JSON object containing the list of projects for a user:
{
"projects": [
{
"id": INTEGER,
"title": STRING,
"user": MONGOID,
"description": STRING,
"start_date": DATE,
"end_date": DATE
}
]
Creates a new project for a user.
Request body (Form or URL Params):
{
"title": STRING
"estimatedTime": INTEGER,
}
Returns a JSON object containing a success or failure message:
{ message: "success" }
Gets a specific project.
Returns a JSON object containing the project details:
{
"project": {
"id": MONGOID,
"user":MONGOID,
"title": STRING,
"description": STRING,
"start_date": DATE,
"end_date": DATE
}
}
Updates a specific project.
Request body (Form or URL Params):
{
"title": STRING,
"timeSpent": INTEGER,
"estimatedTime: INTEGER,
"completed": BOOLEAN,
}
Returns a JSON object containing a success or failure message:
{
"message": "success",
}
Deletes a specific project.
Returns a JSON object containing a success or failure message:
{
"message": "success",
}
Gets a list of all tasks.
Returns a JSON object containing the list of tasks:
{
"tasks": [
{
"id": MONGOID,
"project": MONGOID,
"user": MONGOID,
"title": STRING,
"created": DATE,
"completed": BOOLEAN,
"timeSpent": INTEGER,
"estimatedTime": INTEGER,
}
]
}
Creates a new task.
Request body (Form or URL Params):
{
"project_id": PROJECT_ID,
"title": STRING
"estimatedTime": INTEGER,
"due_date": DATE
}
Returns a JSON object containing a success or failure message:
{ message: "success" }
Deletes the task with the specified id.
Request parameters:
{
"id": TASK_ID,
}
Returns a JSON object containing a success or failure message:
{
"message": "task deleted successfully",
}
Updates the task with the specified id.
Request parameters:
{
"id": MONGOID,
}
Request body (Form or URL Params):
{
"title": STRING,
"timeSpent": INTEGER,
"estimatedTime": INTEGER,
"completed": BOOLEAN,
"project": MONGOID,
}
Returns a JSON object with a success or failure message
{
"message":"success"
}
Creates a new time log.
Request body (Form or URL Params):
{
"task": MONGOID,
"completed": BOOLEAN,
"duration": INTEGER
}
Returns a JSON object containing the ID of the created log entry:
{
"id": MONGOID
}
Updates an existing time log.
Request body (Form or URL Params):
{
"task": MONGOID
"completed": BOOLEAN,
"duration": INTEGER
}
Returns a JSON object containing a success message:
{
"message": "success",
}
Gets an existing time log.
Returns a JSON object containing the time log:
{
"log": {
"_id": MONGOID,
"task": MONGOID,
"user": MONGOID,
"completed": BOOLEAN,
"duration": INTEGER,
"startTime": DATE,
}
}