The source code for the wetland tutorial
JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
migrations
.gitignore
LICENSE
README.md
app.js
package.json
wetland.js

README.md

Wetland tutorial - Inventory manager

This is the source code for the wetland tutorial, in which we build an inventory manager.

You can find the tutorial in the documentation.

Running

To get the tutorial application running, follow these steps:

Clone

First clone this repository to a directory on your machine.

git clone https://github.com/spoonx/wetland-tutorial

Install

Now install the dependencies, and the wetland cli: npm i && npm i -g wetland

Configuration

By default this example uses sqlite, and doesn't need any configuration. To use a different client instead, perform two simple actions:

  1. npm i mysql --save (Or any other client)
  2. Open up wetland.js and change the credentials to yours

Note: Make sure you have an existing database!

Schema

You might want to see the schema before it gets created, you curious creature!

The following command dumps the schema it will create for this dev migration:

wetland migrator dev -d

Note: dev migrations automatically run every time you start the server

Run

Then simply run the server using npm start. You can now access the endpoints documented below.

Endpoints

To make it easier to talk to the api, I have created a list of curl commands.

Create category

POST /category

curl -XPOST -H 'Content-Type: application/json' -d '{
  "name": "electronics"
}' http://127.0.0.1:3000/category

Update category

PATCH /category/:id

curl -XPATCH -H 'Content-Type: application/json' -d '{
  "name": "new name"
}' http://127.0.0.1:3000/category/1

Create product

POST /product

curl -XPOST -H 'Content-Type: application/json' -d '{
  "name": "monitor",
  "categories": [1]
}' http://127.0.0.1:3000/product

Update product

PATCH /product/:id

curl -XPATCH -H 'Content-Type: application/json' -d '{
  "name": "new name"
}' http://127.0.0.1:3000/product/1

Get products

GET /product

curl http://127.0.0.1:3000/product

Get product

GET /product/:id

curl http://127.0.0.1:3000/product/1

Get categories

GET /category

curl http://127.0.0.1:3000/category

Get category

GET /category/:id

curl http://127.0.0.1:3000/category/1

Restock product

PATCH /product/:id/restock

curl -XPATCH -H 'Content-Type: application/json' -d '{
  "quantity": "2"
}' http://127.0.0.1:3000/product/1/restock

Consume product

PATCH /product/:id/consume

curl -XPATCH -H 'Content-Type: application/json' -d '{
  "quantity": "2"
}' http://127.0.0.1:3000/product/1/consume

Get abundant products

GET /product/abundant

curl http://127.0.0.1:3000/product/abundant

Get depleted products

GET /product/depleted

curl http://127.0.0.1:3000/product/depleted

Get abundant products count

GET /product/abundant/count

curl http://127.0.0.1:3000/product/abundant/count

Get depleted products count

GET /product/depleted/count

curl http://127.0.0.1:3000/product/depleted/count

License

MIT