# Configuration module

This module is responsible for DB Configuration fetching and validation. Also this module does environment variable validation.

## Adding new Configuration property

The process of adding new Configuration property involves not only creating an actual DB entry
but also adding some boilerplate for property parsing and validation.

- Create DB migration which will add desired Configuration property to `configuration` table.
  - Use `npm run migration:create` command for this.
  - See `migrations/AddMotdConfigurationProperty.ts` file for an example.
- Alter `helpers/configuration-type.helper.ts` file:
  - add the property to `EConfigurationProperty` enum;
  - define property type in `ConfigurationPropertyValueType` type;
  - define property parser function in `CONFIGURATION_PARSER_FN` map;
    - if the type you're about to store is not `string` and it is some possible common type that is missing (like `boolean` or `number`) - write parser function for it (use `stringParser` function as an example).
- Alter `services/configuration-validation/configuration-validation.service.ts` file:
  - **if new property is optional** - add it to `OPTIONAL_CONFIGURATION_PROPERTIES` const;
  - define validation function for the new property in `VALIDATIONS` service class property;
    - if there are no common functions for your property, you can define custom one in the same service:
      - the method should be `static`;
      - validation will fail if exception is thrown.
    - if there are no common function for your property, and you think that the type of your property is common - define common validator in `COMMON_VALIDATORS` property:
      - basic rule is the same: if exception is thrown - validation has failed;
- If you have written custom validation functions, don't forget to write unit tests.
- Don't forget to describe this property in main `README.md` file.

## Adding new Environment variable

In addition of handling Configuration property validation, this module is also responsible for Environment Variable validation upon service startup.

- Add new property in `.env` file.
- Add new environment variable in `EEnvVariable` enum in `enums/env-variable.enum.ts` file.
- Alter `services/configuration-validation/configuration-validation.service.ts` file:
  - **if new variable is optional** - add it to `OPTIONAL_ENV_PROPERTIES` const;
  - define validation function for the new variable in `ENV_VALIDATIONS` service class property;
    - all stuff regarding common and custom validator function is the same from Configuration properties;
- If you have written custom validation functions, don't forget to write unit tests.
- Of course, don't forget to describe this property in main `README.md` file.
