Tree node structure written in TypeScript. Created with the use as an API, that's written on top of Node.js. Additionally everything is running from inside of Docker containers.
NOTE: GITHUB ACTIONS AND DOCKER REGISTRY USAGE IS FOR TESTING PURPOSES ONLY
Once a Docker image is built and the containers are started, the API container will run Jest tests to see whether the API commands are running properly. If tests will fail the container will fail to spin up. If the tests pass it will be ready to go!
Make sure that the connection to the mongodb container is available!
-
Install Docker
-
Install docker-compose
-
Clone this repository
-
Under cloned repositories directory run
docker-compose up -d --build -
Now it's up and running!
5.1. If you're using Mac or Linux then you can access it under localhost
5.2. If you're using Windows then you need to use a dedicated IP from docker, it can be found using
docker-machine ip
Code : 200 OK
[
{
"children": [
"5ddaada5d6f7c9001edde932"
],
"_id": "5ddaada5d6f7c9001edde931",
"description": "root",
"height": 0,
"__v": 1,
"rootNode": "5ddaada5d6f7c9001edde931"
},
{
"children": [],
"_id": "5ddaada5d6f7c9001edde932",
"description": "a",
"parentNode": "5ddaada5d6f7c9001edde931",
"height": 1,
"__v": 1,
"rootNode": "5ddaada5d6f7c9001edde931"
}
]Code : 200 OK
{
"children": [
{
"children": [
"5ddaada5d6f7c9001edde933"
],
"_id": "5ddaada5d6f7c9001edde932",
"description": "a",
"parentNode": "5ddaada5d6f7c9001edde931",
"height": 1,
"__v": 1,
"rootNode": "5ddaada5d6f7c9001edde931"
}
],
"_id": "5ddaada5d6f7c9001edde931",
"description": "root",
"height": 0,
"__v": 1,
"rootNode": "5ddaada5d6f7c9001edde931"
}Code : 400 Bad Request
If id is missing then an error JSON will be sent back with
{
"error": "Missing parameters!",
"message": "Make sure that key 'id' is specified"
}If id is in incorrect format then an error JSON will be sent back with
{
"error": "Failed to find!",
"message": "Incorrect id format"
}{
"description": "new node",
"parentId": "5ddaada5d6f7c9001edde931"
}- It is possible to create a new root node by not specifying a parentId
Code : 200 OK
{
"children": [],
"_id": "5ddab135d6f7c9001edde936",
"description": "new node",
"parentNode": "5ddaada5d6f7c9001edde931",
"height": 2,
"__v": 0
}Code : 400 Bad Request
If description is missing then an error JSON will be sent back with
{
"error": "Missing parameters!",
"message": "Make sure that key 'description' is specified"
}If parentId is in incorrect format or doesn't exist then an error JSON will be sent back with
{
"error": "Failed to create Node!",
"message": "parentId not found"
}{
"nodeId": "5ddab2894d6d1d002344fce3"
}Code : 200 OK
{
"children": [],
"_id": "5ddab2894d6d1d002344fce3",
"description": "d",
"parentNode": "5ddab2894d6d1d002344fce2",
"height": 3,
"__v": 0,
"rootNode": "5ddab2894d6d1d002344fce0"
}Code : 400 Bad Request
If nodeId is missing then an error JSON will be sent back with
{
"error": "Missing parameters!",
"message": "Make sure that key 'nodeId' is specified"
}If nodeId is in incorrect format then an error JSON will be sent back with
{
"error": "Failed to delete node!",
"message": "Node could not be deleted"
}If nodeId is not found then an error JSON will be sent back with
{
"error": "Failed to delete node!",
"message": "Node was not found"
}{
"childId": "5ddab7f3e75f4c002386c5c4",
"parentId": "5ddab7f3e75f4c002386c5c1"
}- It is possible to swap as the new root node by not specifying a parentId
Code : 200 OK
{
"oldParentNode": "5ddab7f3e75f4c002386c5c3",
"mainNode": "5ddab7f3e75f4c002386c5c4",
"parentNode": "5ddab7f3e75f4c002386c5c1"
}Code : 400 Bad Request
If childId is missing then an error JSON will be sent back with
{
"error": "Missing parameters!",
"message": "Make sure that key 'childId' is specified"
}If node with childId is not found then an error JSON will be sent back with
{
"error": "Node not found!",
"message": "childNodeId can't be found"
}If childId or parentId is in incorrect format then an error JSON will be sent back with
{
"error": "Failed to swap!",
"message": "Child or parent node does not exist"
}- Node.js - Server-side scripting
- MongoDB - General purpose database
- Docker / Docker-compose - Containerized development
- TypeScript - Programming language (superset of JavaScript)
- Jest - Javascript testing framework