A simple inventory tracking web application for a logistics company. Requirements can be found here. A live demo hosted on Repl.it and MondoDB Atlas can be found here.
- Create a warehouse
- Create new item
- Edit existing item
- Delete existing item
- Get a list of all items
- Node/Express backend
- MongoDB/Mongoose database
- Mocha/Chai for testing
First, set up a MongoDB database (online or local)
Then, clone and change directory:
git clone https://github.com/usamaa18/shopify-f2022-backend.git
cd shopify-f2022-backend
Create a .env file and add this line, replacing as neeeded
MONGODB_URI=<connection uri from your database>
Finally install dependencies and start
npm install
npm start
Then you can access the webpage and API on localhost:3000. Note that the sample warehouses on the webpage are only applicable to the project I've hosted on Replit.
Automated testing is performed using Mocha/Chai. To run these tests, simply run:
npm run test
Following test performed on my local machine, with a remote Atlas Database
- ID
- desc
- weight
- length
- width
- height
- warehouseId -- (links to Warehouse)
- ID
- name
- location -- (datatype: GeoJSON)
The REST API to the app is described below.
GET /items
curl --location --request GET 'http://localhost:3000/v1/items'
Status: 200 OK
Content-Type: application/json
[{item1}, {item2}, ...]
GET /items
curl --location --request GET 'http://localhost:3000/v1/items'
Status: 200 OK
Content-Type: application/json
[]
POST /items
curl --location --request POST 'http://localhost:3000/v1/items' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'description=iPhone 13' \
--data-urlencode 'weight=3.3' \
--data-urlencode 'length=10' \
--data-urlencode 'width=5' \
--data-urlencode 'height=3' \
--data-urlencode 'warehouseId=6281cff83d222c6c47382462'
Status: 200 OK
Content-Type: application/json
{
"desc": "iPhone 13",
"weight": 3.3,
"length": 10,
"width": 5,
"height": 3,
"warehouseId": "6281cff83d222c6c47382462",
"_id": "62826bf6b3f9087a71667a46",
"__v": 0
}
POST /items/{id}
curl --location --request POST 'http://localhost:3000/v1/items/62826bf6b3f9087a71667a46' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'weight=20'
Status: 200 OK
Content-Type: application/json
{
"_id": "62826bf6b3f9087a71667a46",
"desc": "iPhone 13",
"weight": 20,
"length": 10,
"width": 5,
"height": 3,
"warehouseId": "6281cff83d222c6c47382462",
"__v": 0
}
DELETE /items/{id}
curl --location --request DELETE 'http://localhost:3000/v1/items/62826bf6b3f9087a71667a46'
Status: 200 OK
Content-Type: text/html
Deleted item successfully
DELETE /items/{id}
curl --location --request DELETE 'http://localhost:3000/v1/items/62826bf6b3f9087a71667a46'
Status: 400 BAD REQUEST
Content-Type: text/html
Invalid item (itemId not found in DB)
POST /items/{id}
curl --location --request POST 'http://localhost:3000/v1/items/62826bf6b3f9087a71667a46' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'weight=20'
Status: 404 NOT FOUND
Content-Type: text/html
Invalid item (itemId not found in DB)
POST /warehouses
curl --location --request POST 'http://localhost:3000/v1/warehouses' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'name=Montreal' \
--data-urlencode 'longitude=73.5673' \
--data-urlencode 'latitude=45.5017'
Status: 200 OK
Content-Type: application/json
{
"name": "Montreal",
"location": {
"type": "Point",
"coordinates": [
73.5673,
45.5017
]
},
"_id": "62826ed0b3f9087a71667a50",
"__v": 0
}
- Used express-generator.
- Used mongoose-id-validator.
- Used Shopify's logo as favicon.ico. No trademark infringement intended.