There are 2 main functions for this service:
- Managing ShoppingCentre
- Managing Assets for ShoppingCentre
Refer src/schemas/schema.js
for detailed JSON schema.
-
ShoppingCentre:
- A shopping typically has name, description an address.
- It may have many assets associated with it
-
Asset:
- An asset has name, description
- It also has physical dimension attributes
- It has properties describing its configuration and capability - adSpotLength, maxAdLoopTime, maxAdvertisers, beaconRFIDEnabled etc.
- It has properties which describe its pyhysical location in the shopping-centre like: floor, mainCorridor, shopNumber etc.
- It has properties to describe how asset is displayed or mounted
- Uses jwt for authenticating requests. Token is set
x-access-token
in request header
- Node 6.10 (node 6 should work fine too)
- Postgresql 9.6 (9.4 and above should work too)
Path | Method |
---|---|
/shopping-centres/{id} | GET |
/shopping-centres | POST |
/shopping-centres/{id}/assets | GET |
/assets/{id} | GET |
/assets | POST |
/assets/{id} | PUT |
/authenticate | POST |
├── src - service source files
| ├── db - migration files (using sequelize)
| ├── schemas - request/response parsers and schema validators
| ├── models
| ├── controllers
├── test - integration and unit tests (using mocha/shouldjs)
- Clone the repo
npm i
to install node packages- Setup Development DB
createdb inventory_store_development
node_modules/.bin/sequelize db:migrate
node_modules/.bin/sequelize db:seed:all
- Run
npm start
to start the app - Run
npm test
to run specs - Run
npm run lint
to run es6 linter
- App config.js at
src/config.js
- DB config at
configs/database.json
- Create db user
CREATE USER developer WITH PASSWORD 'developer';
- Create dev db
- From psql cli -
CREATE DATABASE inventory_store_development;
- OR from terminal
createdb inventory_store_development
- From psql cli -
- grant access
GRANT ALL PRIVILEGES ON DATABASE inventory_store_development to developer;
- Run migrations
node_modules/.bin/sequelize db:migrate
- Create test user and dummy data
node_modules/.bin/sequelize db:seed:all
- Creates dummy users
testuser1/roger@123
- Creates dummy users
- There are unit test and integration tests for controller and models
- Setup Test DB
createdb inventory_store_test
NODE_ENV=test node_modules/.bin/sequelize db:migrate
npm test
to run tests
curl -X POST \
http://localhost:3000/authenticate \
-H 'content-type: application/json' \
-d '{
"username": "testuser1",
"password": "dummy"
}'
curl -X POST \
http://localhost:3000/shopping-centres \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTAsImlhdCI6MTUxMjUwNzg2NywiZXhwIjoxNTEyNTExNDY3fQ.OtQaFY4sB1aj9DDjpXe_9oRykZeL14MM_qM1V5Z6e7Q' \
-d '{
"name": "Westfield",
"address": {
"streetNumber": "11",
"streetName": "Victoria",
"suburb": "Chatswood",
"postCode": 2065,
"state": "NSW",
"country": "AUS"
}
}'
curl -X GET \
http://localhost:3000/shopping-centres/169 \
-H 'x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTAsImlhdCI6MTUxMjUwNzg2NywiZXhwIjoxNTEyNTExNDY3fQ.OtQaFY4sB1aj9DDjpXe_9oRykZeL14MM_qM1V5Z6e7Q'
curl -X POST \
http://localhost:3000/assets \
-H 'content-type: application/json' \
-H 'x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTEyNTE1MTE1LCJleHAiOjE1MTI1MTg3MTV9.rxpMiN2KikGrHipdPsbk2_EPu3pcwKgs4UFBc_amHsY' \
-d '{
"name": "Asset1",
"ShoppingCentreId": 6,
"status": "active",
"dimensions": {
"height": 55,
"width": 47,
"unit": "cm"
},
"location": {
"floor": "B-2"
}
}'
- Enhance Asset model. Schema allows for more properties on the object
- API Docs using Swagger
- Tests
- improve test setup
- DB improvments
- whitelisting attributes to update at model level
- fix foreignKey ShoppingCentreId to be lowercase
- Route to create users