- 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