- Create a file named ".env.development.local" with the following text as env var
# PORT
PORT = 3000
# TOKEN
SECRET_KEY = secretKey
API_KEY = myApiKey
KRAKEN_API_KEY = EltgJ5G8m44IzwE6UN2Y4B4NjPW77Zk6FJK3lL23
# LOG
LOG_FORMAT = dev
LOG_DIR = ../logs
# CORS
ORIGIN = *
CREDENTIALS = true
-
npm install
andnpm run dev
This will start with the env var that has our API_KEY and KRAKEN_API_KEY (Yes they should not be in the repo but this is test) -
Go to
/src/http/report.http
and use REST Client in VS Code to interact with the API, that is POST {{ baseURL }}/report/norwich-pear-tree the API_KEY=myApiKey is already attached. (Or call the api by any tool you like)
The files with arrows bellow are the important ones
β
βββπ .vscode
β βββ launch.json
β βββ settings.json
β
βββπ src
β βββπ config
β β βββ index.ts <-- remember to config env var api keys if not in dev
β β
β βββπ controllers
| | βββ report.controller.ts <-- report api (the main task in the test)
| | βββ krakenflex.controller.ts <-- all krakenflex api
β β βββ auth.controller.ts // ignore auth
β β βββ users.controller.ts // ignore users
β β
β βββπ dtos
β β βββ users.dto.ts
β β
β βββπ exceptions
β β βββ httpException.ts
β β
β βββπ http
β β βββ auth.http
β β βββ users.http
β β
β βββπ interfaces
β β βββ event.interface.ts <-- define event type
β β βββ siteInfo.interface.ts <-- define siteInfo type
β β βββ apiResponse.interface.ts <-- define apiResponse type
β β βββ auth.interface.ts
β β βββ routes.interface.ts
β β βββ users.interface.ts
β β
β βββπ middlewares
β β βββ validApiKey.middleware.ts <-- validApiKey middleware
β β βββ auth.middleware.ts
β β βββ error.middleware.ts
β β βββ validation.middleware.ts
β β
β βββπ models
β β βββ users.model.ts
β β
β βββπ routes
β β βββ report.route.ts <-- report route
β β βββ krakenflex.route.ts <-- krakenflex api route
β β βββ auth.route.ts
β β βββ users.route.ts
β β
β βββπ services
β β βββ report.service.ts <-- filter and report logic
β β βββ krakenflex.service.ts <-- service to call krakenflex api
β β βββ auth.service.ts
β β βββ users.service.ts
β β
β βββπ test
β β βββ report.test.ts <- report test
β β
β βββπ utils
β β βββ logger.ts
β β βββ vaildateEnv.ts
β β
β βββ app.ts
β βββ server.ts
β
βββ .dockerignore
βββ .editorconfig
βββ .env.development.local
βββ .env.production.local
βββ .env.test.local
βββ .eslintignore
βββ .eslintrc
βββ .gitignore
βββ .huskyrc
βββ .lintstagedrc.json
βββ .prettierrc
βββ .swcrc
βββ docker-compose.yml
βββ Dockerfile.dev
βββ Dockerfile.prod
βββ ecosystem.config.js
βββ jest.config.js
βββ Makefile
βββ nginx.conf
βββ nodemon.json
βββ package-lock.json
βββ package.json
βββ swagger.yaml
βββ tsconfig.json
It has all the kraken api working in swagger
GET /outages
which returns all outages in our systemGET /site-info/{siteId}
which returns specific information about a sitePOST /site-outages/{siteId}
which expects outages for a specific site to be posted to it
And it's own API working in report.http
POST /report/{siteId}
Given a siteId, report the relevant outages events toPOST /site-outages/{siteId}
run npm test
to test or try it in report.http
Site:
siteId: readable name, e.g "id: norwich-pear-tree"
A siteId has multiple deviceId
Device:
id (deviceId): hex code of devices, e.g "id": "002b28fc-283c-47ec-9af2-ea287336dc1b",
name (deviceName): readable name, e.g "name": "Battery 1"
A deviceId has mulitple outages events with begin and end timestamp
Event:
end: timestamp string
begin: timestamp string
id (deviceId)
- Run the Server in production mode :
npm run start
- Run the Server in development mode :
npm run dev
with dev api keys - Run all unit-tests :
npm test
- Check for linting errors :
npm run lint
- Fix for linting :
npm run lint:fix