This documentation covers the technical apects of code.

This server app follows the MVC pattern. (M => Model, V => Controller, C => Service)

# Install

TODO
node ace add ou truc comme ca
preload
la liste des var d'env

```

# Config

`config/` contains predefined configs for your adonisjs app. Those will be overitten by any config in app's config dir.

# Modules

## CRUD

### Extra data

To return additionnal database data in model serialization, you need to :

- add extra data when querying the database (see [Lucid doc](https://lucid.adonisjs.com/docs/) , eg [withCount](https://lucid.adonisjs.com/docs/model-query-builder#withcount))
- declare a getter on the model that exposes the extra data

## Auth

Auth is managed by AuthContext.

In http server context, AuthContext is populated bu AuthMiddleware.

## API exception

TODO

## Test

`tests/` contains utilitaries to help write tests. It does not contain actual tests. Tests live in `*.test.ts` files

## Emails

Emails are build with two technologies : [edge.js](https://edgejs.dev) and [MJML](https://mjml.io/). MJML have constraints, some have been purposefully broken to match the design spec.

Previews are visible on a running server at `/event` (eg : [https://api.libelaw.fr/event](https://api.libelaw.fr/event))

Most emails are based on `default_html.edge` that contains components which can be activated or not. This is controlled by the data returned in `emailPayload()` in an AKEvent (eg: `ResourceMessageNewEvent` activates two components : message & missionSmall)

# Caveats

- Model serialization : Never return model objects in controller responses, `serialize()` them first. Otherwise model getters like `Mission.viewerStatus()` won't have access to `AuthContext` as it will be closed before serialization.

- Due to the nature of typescript, some hacks have been done in the akago framework to make things generic. It impacts the discoverability of the features (eg: static overrides of generic classes).

# Recommended additionnal packages

- [@akago/adonisjs-drhttp](https://www.npmjs.com/package/@akago/adonisjs-drhttp)
- [@akago/adonisjs-log-http](https://www.npmjs.com/package/@akago/adonisjs-log-http)
```
