2020-08-12 10:56:12 +02:00
|
|
|
# DeFinMa - API
|
2020-01-14 16:31:14 +01:00
|
|
|
|
2020-08-28 16:50:33 +02:00
|
|
|
This is the API to access the database of the digital fingerprint of plastics project. A deep insight into the project
|
|
|
|
structure can be gained in the
|
|
|
|
[Bachelor Thesis](https://definma.apps.de1.bosch-iot-cloud.com/assets/docs/Veit-Lukas_Bachelor-Thesis.pdf).
|
2020-01-14 16:31:14 +01:00
|
|
|
|
|
|
|
## API documentation
|
|
|
|
|
2020-08-28 16:50:33 +02:00
|
|
|
The API is documented using the Open API Specification 3.0.2 in the [api](./api) and hosted together with the API under
|
|
|
|
the `/api-doc` path. The online version can be found [here](https://definma-api.apps.de1.bosch-iot-cloud.com/api-doc).
|
|
|
|
The files are automatically bundled and validated when starting the server.
|
2020-01-14 16:31:14 +01:00
|
|
|
|
|
|
|
## Testing
|
|
|
|
|
|
|
|
Testing is done with mocha and can be executed using `npm test`.
|
2020-08-28 16:50:33 +02:00
|
|
|
|
|
|
|
## General structure
|
|
|
|
|
2020-09-03 16:26:16 +02:00
|
|
|
[index.ts](./src/index.ts) is executed when starting the server. It includes all setup tasks, registers middleware,
|
2020-08-28 16:50:33 +02:00
|
|
|
routes and error handlers. Setting the `NODE_ENV` environment variable allows starting the server either in
|
|
|
|
`production`, `development` or `test` mode.
|
|
|
|
|
|
|
|
All route files including the corresponding test files are in the [routes](./src/routes) folder. The
|
|
|
|
[validate](./src/routes/validate) folder stores Joi validations for data input and output.
|
|
|
|
|
|
|
|
[models](./src/models) keeps all Mongoose database collection models.
|
|
|
|
|
|
|
|
[helpers](./src/helpers) includes functions needed in multiple places like the authorization done for every route,
|
|
|
|
csv conversion and object flattening as well as a mail service, registering an email address using the mail service on
|
|
|
|
the BIC and replacing it with a logging statement in development.
|
|
|
|
|
|
|
|
[test](./src/test) holds files for testing like the test database `db.json` loaded freshly for every test case and
|
|
|
|
a helper utilized for easier testing. `loadDev` loads the `db.json` into the `development` database for a fresh start.
|