A simple task-management demo. Implemented with Clean Architecture in mind.
Clone the repo:
git clone https://github.com/coldplayz/neyo-task-management.git
cd
to the clone repo and install dependencies:
cd neyo-task-management
npm install
Before starting the server, ensure you have an instance of MongoDB running (tested with MongoDB v6.1.0).
Also, you can optionally set the following environment variables:
Name | Description |
---|---|
PORT |
Optional. Server port. Default: 3456 . |
Start the dev server:
npm run dev
Make requests to the endpoints
curl http://localhost:3456/
That's the sanity check endpoint. It returns a simple object:
{
"success": true,
"data": "LIVE"
}
The API also exposes a socket stream for notifying of events, using socket.io.
These events are related to CRUD operations on the API, and include:
- createUser
- getUsers
- getUserById
- editUserById
- deleteUserById
- login
- logout
- refreshToken
- createTask
- getTasks
- getTaskById
- editTaskById
- deleteTaskById
There's also a generic apiEvent
event that is emitted after a request
to the sanity check endpoint (/
).
Subscribe to any of these events onbthe clients to get updates, with some support for connection recovery.
Create a new user
POST /api/v1/users
Name | Type | Description |
---|---|---|
firstName |
string |
Required. User's first name |
lastName |
string |
Required. User's last name |
email |
string |
Required. User's unique email |
password |
string |
Required. User's password |
Status: 401 Unauthorized
Status: 201 Created
Returns the newly created user object.
Get multiple users, filterable by query params. Public at present for testing purposes.
GET /api/v1/users
Name | Type | Description |
---|---|---|
firstName |
string |
Optional. User's first name |
lastName |
string |
Optional. User's last name |
email |
string |
Optional. User's unique email |
role |
string |
Optional. User's role |
Status: 500 Internal Server Error
Status: 200 OK
Returns user objects meeting the query criteria, or all if no criteria.
Get a specific user using their unique database ID. Public at present for testing purposes.
GET /api/v1/users/:id
Status: 404 Not Found
Status: 200 OK
Returns a specific user object.
Update a specific user's data. Public at present for testing purposes.
PUT /api/v1/users/:id
Name | Type | Description |
---|---|---|
firstName |
string |
Optional. User's first name |
lastName |
string |
Optional. User's last name |
email |
string |
Optional. User's unique email |
password |
string |
Optional. User's password |
Status: 404 Not Found
Status: 200 OK
Returns the updated user object.
Remove a specific user using their unique database ID. Public at present for testing purposes.
DELETE /api/v1/users/:id
Status: 404 Not Found
Status: 204 No Content
Removes the specific user from the database.
Logs a user in by providing access and refresh tokens.
POST /api/v1/auth/login
Name | Type | Description |
---|---|---|
email |
string |
Required. User's unique email |
password |
string |
Required. User's password |
Status: 401 Unauthorized
Status: 200 OK
Returns access and refresh tokens for accessing private endpoints.
Sign a logged-in user out of their session.
POST /api/v1/auth/logout
Status: 401 Unauthorized
Status: 200 OK
For a valid refresh token, generate and return a new access (and refresh) token.
GET /api/v1/auth/refresh-token
Status: 401 Unauthorized
Status: 201 Created
Returns new access and refresh tokens.
Create a new user task.
POST /api/v1/tasks
Name | Type | Description |
---|---|---|
description |
string |
Required. Details of the task |
Status: 401 Unauthorized
Status: 201 Created
Returns the newly created task object.
Get multiple tasks, filterable by query params and specific to the authenticated user.
GET /api/v1/tasks
Name | Type | Description |
---|---|---|
done |
boolean |
Optional. Task pending state. |
Status: 401 Unauthorized
Status: 200 OK
Returns task objects meeting the query criteria, or all if no criteria.
Get a specific task using their unique database ID. Public at present for testing purposes.
GET /api/v1/tasks/:id
Status: 404 Not Found | 401 Unauthorized
Status: 200 OK
Returns a specific task object.
Update a specific user task.
PUT /api/v1/tasks/:id
Name | Type | Description |
---|---|---|
done |
boolean |
Optional. Task pending state. |
description |
string |
Optional. Task details. |
Status: 404 Not Found | 401 Unauthorized
Status: 200 OK
Returns the updated task object.
Remove a specific task using their unique database ID.
DELETE /api/v1/tasks/:id
Status: 404 Not Found | 401 Unauthorized
Status: 204 No Content
Removes the specific task from the database.