# App Useful Reference
## scripts
- console:dev
> this runs the console version of the backend (used for cron jobs) in development mode (debug)
- console
> Same as above, prod mode
- containers:restart
> Tear down and restart docker containers (API and DB)
- initialize:db
> runs above script and then runs migrations on a new database container
- prebuild
> cleans up generated files from previous builds
- build
> builds the project (compile TS and etc into its final executable form)
- format:check
> Check code style
- format:fix
> automatically fix code style (if possible)
- format:ci
> calls format:check
- start
> starts the compiled version (needs to be built before),
- start:dev
> builds and runs the code in development mode (it hot-reloads on changes),
- start:debug
> runs the compiled version in debug mode,
- start:prod
> command used on the deployed version to run the code,
- start:build
> same as above, but building the code before running it (saves one step)
- typecheck
> Checks for typescript errors
- run-checks
> check linter, typescript and code style errors,
- lint:check
> check linter errors,
- lint:fix
> automatically fixes linter errors (if possible),
- lint
> calls the script below
- lint:ci
>calls lint:check :joy:
- test
> runs all types of tests,
- test:ci
> calls the script above (used on CI),
- test:coverage
> runs tests and calculates test coverage
- test:watch
> runs tests in watch mode
- test:debug
> runs tests in debug mode
- test:e2e:memory
> runs end-to-end tests using a "memory" implementation of a database.
- **DANGER**: test:e2e:db
> run end-to-end tests using the real local database.
> **BE EXTREMELY CAREFUL NOT TO RUN THIS IF CONNECTED TO PROD'S DATABASE. IT WILL WIPE IT.**
- test:integration
> runs integration tests (agains third parties apis, they are skipped. Just unskip locally to test everything works and skip again afterwards)
> test:unitary: runs unitary tests (specific classes or functions)
- seed
> populates the database with basic data (products, an admin, raw feeding combinations...)
- migration:create
> Detects changes on entities and generates a migration file
- migration:run
> applies all migrations that are not applied yet
- migration:down
> reverts the latest migration. Run multiple time if needs to revert multiple migrations.
- precommit
> not used. Should check tests, typescript, lint... etc on commit.
## How to connect to prod/staging from local
First you need to have access to the kubernetes cluster. After you've successfully completed [this guide](https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html): you have to create a proxy from your localhost to the staging/beta/production pod. To do that, use this command:
`kubectl port-forward --namespace=ENVIRONMENT $(kubectl --namespace=ENVIRONMENT get pods | grep db-proxy | cut -d ' ' -f 1) 5432:5432`
with `ENVIRONMENT` being either production, staging or beta
After that, you have to change the environment variables to use the appropriate credentials to the desired environment. (I'll send those to you).
## how to dump and restore
- Dump
> On DBeaver, right click on the database name you wish to backup. Hit "tools" -> "backup". Select "public" and hit "next". Hit "Start". Boom!
- Restore
> On DBeaver, right click on the database name you wish to dump your backup onto. Hit "tools" -> "restore". Select your backup file and hit next. Remember the check the "CLEAN (DROP) DATABASE..." option. -> next -> next... done
## How to deploy to the different environments
- Staging: Merge to main branch
- Beta: Merge to beta branch
- Prod: create a new tag
## Different third-parties and where to find them in code
- Klaviyo
> LeadsTrackerModule (LeadsTracker, LeadsTrackerFake, LeadsTrackerKlaviyo)
- Chargebee
> PaymentChargerModule (PaymentCharger, PaymentChargerFake, PaymentChargerChargebee)
- Stripe
> CardPaymentChargerModule (CardPaymentCharger, CardPaymentChargerFake, CardPaymentChargerReal)
- Taxjar
> AddressValidatorModule and TaxesCalculatorModule (AddressValidator, AddressValidatorFake, AddressValidatorTaxJar, TaxesCalculator, TaxesCalculatorFake, TaxesCalculatorTaxJar)
- Mailgun
> EmailSenderModule (EmailSender, EmailSenderFake, EmailSenderMailGun)
- NeverBounce
> EmailValidatorModule (EmailValidator, EmailValidatorFake, EmailValidatorNeverBounce)
- Sentry
> ExternalLogger, ExternalLoggerFake, ExternalLoggerSentry
- Cloudwatch
> InternalLogger
- Different Repos and their purposes
- Portal
> frontend of the client-side app
- Backoffice
> frontend of the admin-side app
- Api-core
> backend of the app
- Emails
> repository for the email templates
- Infrasturcture
> repository that holds the terraform files for the infrastructure of the whole app. (AWS resources, config, etc.)