# Developers

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

## Git

Git *flow* branch description:

* **master** (production)
  * hotfix/task
* **develop** (development)
  * feature/task
  * release/version

## Installation

Biometrid requires [Node.js](https://nodejs.org/) v14+, [NPM](https://www.npmjs.com) v6+ and [MongoDB](https://www.mongodb.com) v4+ to run.

```haskell
$ git clone git@bitbucket.org:polygon_/biometridon_v2.git
$ cd biometridon_v2
$ npm install
```

## Environment variables

There are several variables to be configured, from Database connection to Biometric and Twilio settings. Check below an example.

```javascript
// .env.example

APP_URL=http://localhost:3333

HOST=localhost
PORT=3333

API_URL=${APP_URL}/api
WEBVIEW_URL=${APP_URL}/webview

APP_NAME=Biometrid
NODE_ENV=development
CACHE_VIEWS=false
SESSION_DRIVER=cookie
HASH_DRIVER=bcrypt
SAVE_AUDITS=true
SAVE_LOGS=true

DB_CONNECTION=mongodb
DB_HOST=localhost
DB_PORT=27017
DB_USER=
DB_PASSWORD=
DB_DATABASE=biometrid
DB_CONNECTION_STRING=mongodb://127.0.0.1:27017/biometrid

# x509 CERTIFICATES
DB_SSL=false
DB_AUTH_MECHANISM=
DATABASE_X509_USER=

## Following paths most be in root project directory
DATABASE_PATH_LOCAL_SSL_KEY=/certificates/client.pem
DATABASE_PATH_LOCAL_SSL_CERT=/certificates/client.crt
DATABASE_PATH_LOCAL_SSL_CA=/certificates/ca.crt

# JWT DEFAULT SETTINGS FOR CLIENT TOKEN AND USER TOKEN
APP_KEY_CLIENT=<ask for it>
APP_KEY_USER=<ask for it>
JWT_EXPIRE_CLIENT=1h
JWT_EXPIRE_USER=1d

# MAIL SETTINGS
MAIL_CONNECTION=smtp
MAIL_PORT=
MAIL_HOST=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_FROM=
MAIL_FROM_NAME=

# API PROCESSES SETTINGS
API_PROCESS_LIFETIME=2
API_PROCESS_SCHEDULED_TIME=60

# UPLOAD SETTINGS
FILE_MAX_SIZE=2
IMAGE_FILE_TYPE_ALLOWED=jpg,jpeg,png
AUDIO_FILE_TYPE_ALLOWED=wav
DOC_FILE_TYPE_ALLOWED=pdf

# TEMP UPLOAD FOLDER
TMP_UPLOADS_PATH=tmp/uploads/

# FOLDER TO PLACE UPLOADED FILES
UPLOADS_PATH=uploads

# CRON SETTINGS
CRON_SCHEDULE_UNLOCK="*/10 * * * *"
CRON_SCHEDULE_TMP_DELETE="0 0 0 * * *"
CRON_SCHEDULE_DELETE_PROCESSES="0 2 * * *"

# PROVIDERS
VID01_ACCOUNT=
VID01_KEY=
VID01_SECRET=
VID01_SMSACCOUNTSID=
VID01_SMSAUTHTOKEN=
VID01_SMSFROMNUMBER=
FACE02_TOKEN=
FACE01_TOKEN=
OCR01_ACCOUNTID=
OCR02_COMPANY=
OCR02_USER=
OCR02_PWD=
```

## Start

```haskell
$ mongod
$ adonis biometrid:install
$ adonis polygon:install
$ npm run dev
$ npm run watch
$ node ace run:scheduler
```

## Testing

For testing purposes, please create file **.env.testing.**

```javascript
// .env.testing.example

HOST=localhost
PORT=3334
NODE_ENV=testing
APP_URL=http://${HOST}:${PORT}

#IDCARD_FRONT='path_from_tmp_folder.jpg'
#IDCARD_BACK='path_from_tmp_folder.jpg'
#SELFIE='path_from_tmp_folder.jpg'
#PHOTO='path_from_tmp_folder.jpg' (IDCARD photo)
#PHOTO_FAKE='path_from_tmp_folder.jpg' (another person photo)
#FACEMAP='facemap.txt'
PHONE='+351930000000'
EMAIL='admin@polygon.pt'

DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_USER=
DB_PASSWORD=
DB_DATABASE=biometridTesting
DB_CONNECTION_STRING=mongodb://127.0.0.1:27017/biometridTesting

SAVE_LOGS=true
```

Be sure that you have [AdonisJs Cli](https://github.com/adonisjs/adonis-cli) installed on your system.

```haskell
$ npm run lint
$ npm run test
```

## Docker

Change **.env** HOST to 0.0.0.0.

```haskell
$ docker-compose build && docker-compose up -d
```
