# 4781 liftexperts Backend

Backend for the company "liftexperts", where they can manage their customers, elevators and according reports.\
The Backend provides a full REST API with permissions, filtering, paginantion and more.\
It's is built using a [Strapi v4](https://strapi.io/) Instance with a Maria oder MySQL Database.

The Frontend can be found here: [Production liftexperts Frontend](url)\
The according frontend repo is here: [REPO liftexperts FrontEnd](https://git.raumgleiter.com/web/apps/4781-liftexperts/4781-liftexperts-frontend)

The project whas created bootstrapped with [create-strapi-app](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/installation/cli.html#creating-a-strapi-project) using the following [Documentation](https://strapi.io/blog/configuring-strapi-mysql-database).

## How to use

#### Collections and Components
- Collections
    - Elevators (Aufzüge)
    - Reports (Berichte)
    - Companies (Firma / Kunde)
    - Manufacturer (Hersteller)
    - Contacts (Kontakte)
    - Users ( not needed atm)
- Single Types
    - Statische Daten (Logo, Vorteile und Nutzen Liftexperts, Teammitglieder)
- Components
    - global
        - adresse
        - angebot
        - team
        - teammitglied
        - usp
    - elevator
        - cabin
        - handrails (containing multiple handlauf elements)
        - handlauf
        - shaft
    - esba
        - esba-all (containing all esba rows)
        - single esba elements (esba_1 to esba_7)
    - report
        - esba
        - section-cabin
        - section-cabincontrol
        - section-cablebuffer
        - section-cables-pulleys
        - section-controller
        - section-counterweight
        - section-custom
        - section-diverter-pulley
        - section-door-fotocell
        - section-door-lightgrid
        - section-door-pneumabarrier
        - section-doordrive
        - section-doormagnets
        - section-drivebuffer
        - section-driveparts
        - section-emergencysystem
        - section-floorcontrols
        - section-gi-cabin
        - section-gi-cntweight
        - section-handrails
        - section-hanging-cables
        - section-hydraulic-cylinder
        - section-hydraulic-unit
        - section-lubricators
        - section-machineroom
        - section-malfunctions
        - section-motor
        - section-recommendation
        - section-regulator
        - section-service
        - section-shaftdoors
        - section-shaftpit
        - section-speedlimiter
        - section-summary
    - report-choices
        - action-needed
        - parts
    - report-recommendation
        - longterm
        - massnahme
        - midterm
        - shortterm

General Strapi API [Documentation](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/filtering-locale-publication.html#complex-filtering)

## DEV requirements
- Node.js
- NPM or YARN
- Git

## Available Scripts
Strapi comes with a full featured [Command Line Interface](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html) (CLI) which lets you scaffold and manage your project in seconds.

### `npm run develop`

Local development mode:
Start your Strapi application with autoReload enabled. [Learn more](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html#strapi-develop)

### `npm run start`

Start your Strapi application with autoReload disabled. [Learn more](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html#strapi-start)

### `build`

Build your admin panel. [Learn more](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html#strapi-build)


## Endpoints
The REST API allows accessing the content-types through API endpoints. 
Strapi automatically creates API endpoints when a content-type is created. [API parameters](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/api-parameters.html) can be used when querying API endpoints to refine the results.

`Get Static Data` https://liftexperts-backend.herokuapp.com/api/static-data \
`Get Elevator by Id` https://liftexperts-backend.herokuapp.com/api/elevators/:elevatorId (elevatorId: Custom system_id / Anlagennummer)\
`Get Report by Id` https://liftexperts-backend.herokuapp.com/api/reports/:reportId (reportId: Auto Strapi Collection Id)

## ⚙️ Deployment

### Production

#### Database
The database is hosted on [Hostpoint](https://hostpoint.ch) or any other MySQL/MariaDB cabable instance. Credentials are stored in the project .env file and needs following variables:
- DATABASE_HOST
- DATABASE_PORT
- DATABASE_NAME
- DATABASE_USERNAME
- DATABASE_PASSWORD
- DATABASE_SSL

#### Application
The application is deployed on heroku via the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) directly to the remote via "git push" from the local git repository.
Heroku then loads the npm modules needed, builds the application and deploys it.
Alternatively the App can be built locally and loaded to a standard Webserver via FTP/SFTP.

Application needs following variables stored in the .env project file:\
HOST=0.0.0.0\
PORT=1337\
APP_KEYS=vu6Q7G0YtayPghJfhxhGUw==,XW5CIY6Sc/xsT84ho8yS5g==,R4FQJRVBAqMHjiK9qeqyJQ==,9JrZ2t8x3XslwdVT1THiWg==\
API_TOKEN_SALT=wL5AHaetP/gcSrNx48147w==\
ADMIN_JWT_SECRET=dquPrRzxuhlKhhXwYSEbGw==\
JWT_SECRET=G3wUdP4yFDWxl9O0KAS+sg==\

#### Blob-Storage (Media File Storage)
The Media files are stored on an Azure Blob-Storage instance. Credentials are stored in the project .env file and needs following variables:
- STORAGE_ACCOUNT
- STORAGE_ACCOUNT_KEY
- STORAGE_URL
- STORAGE_CONTAINER_NAME

## Update Strapi

Strapi can be updated to latest Version by following the [Guide](https://docs.strapi.io/developer-docs/latest/update-migration-guides/update-version.html).
Please check if you need to make version dependant manual changes in the [Migration Guide](https://docs.strapi.io/developer-docs/latest/update-migration-guides/migration-guides.html)
