> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Collection Notifications

`notifications` contient les avis affichés en haut du tableau de bord des projets d'un utilisateur. Un document correspond à un avis pour un utilisateur, identifié par sa `key`. Seul le service `notifications` accède à la collection (`services/notifications/app/js/Notifications.js`) ; `web` et `third-party-datastore` appellent son API HTTP. Il n'y a pas de schéma Mongoose.

#### Champs

| Champ | Type | Signification | Source |
| - | - | - | - |
| `_id` | ObjectId | Id de l'avis. `web` marque un avis comme lu grâce à cet id. | `Notifications.js:58-65` |
| `user_id` | ObjectId | L'utilisateur qui voit l'avis. | `Notifications.js:26` |
| `key` | String | Identifie l'avis, par exemple `project-invite-<inviteId>`. L'upsert conserve un document par `user_id` et `key` ; il n'y a pas d'index unique. | `Notifications.js:27`, `:51-55` |
| `templateKey` | String | L'avis que le frontend affiche. Supprimé lorsque l'avis est lu ou ignoré ; le document reste. | `Notifications.js:29`, `:63`, `:72`, `:78` |
| `messageOpts` | Object | Valeurs du texte de l'avis, selon `templateKey` (pour une invitation à un projet : `userName`, `projectName`, `projectId`, `token`). Supprimé lorsque l'utilisateur ignore l'avis par son id. | `Notifications.js:28`, `:63` |
| `expires` | Date | Facultatif. L'index TTL supprime le document après cette date. | `Notifications.js:35-50` |

#### Qui l'écrit

| Code | Ce qu'il fait |
| - | - |
| `Notifications.js:20-56` (`addNotification`) | `POST /user/:user_id` (`services/notifications/app.ts:29`). Upsert par `user_id` + `key`. Si un document avec cette clé existe déjà, il n'est réécrit que si l'appelant envoie `forceCreate`. |
| `Notifications.js:58-65` (`removeNotificationId`) | `DELETE /user/:user_id/notification/:notification_id` (`app.ts:31-34`): supprime `templateKey` et `messageOpts`. |
| `Notifications.js:67-80` | `DELETE /user/:user_id` et `DELETE /key/:key` (`app.ts:35-36`): suppriment `templateKey` par clé. |
| `Notifications.js:87-100` | `DELETE /key/:key/bulk` (`app.ts:38-41`) supprime les avis non lus ayant une clé ; `deleteNotificationByKeyOnly` supprime un document par clé. |
| `services/web/app/src/Features/Notifications/NotificationsHandler.mjs:33-66` | Côté `web` de `addNotification`. Envoie `forceCreate: true` sauf si l'appelant passe `false`. |
| `services/third-party-datastore/app/js/QueueWorker.mjs:46-58` | Notre synchronisation Dropbox : lorsqu'elle dissocie un compte Dropbox, elle publie directement l'avis `dropbox-unlinked`. |

Avis créés par CE et nos modules :

| `key` | `templateKey` | Créé dans |
| - | - | - |
| `project-invite-<inviteId>` | `notification_project_invite`, expire avec l'invitation | `services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs:40-42`, construit dans `services/web/app/src/Features/Notifications/NotificationsBuilder.mjs:100-122`. Uniquement si l'e-mail invité appartient à un utilisateur existant. |
| `tpdsFileLimit-<userId>` | `notification_tpds_file_limit` | `services/web/app/src/Features/ThirdPartyDataStore/TpdsController.mjs:118-124` (une mise à jour Dropbox ferait dépasser à un projet la limite de fichiers), `NotificationsBuilder.mjs:175-195` |
| `dropboxDuplicateProjectNames-<userId>` | `notification_dropbox_duplicate_project_names` | `services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.mjs:160-169`, `NotificationsBuilder.mjs:10-30` |
| `dropbox-unlinked` | `dropbox_unlinked_because_access_denied`, `dropbox_unlinked_because_full` ou `dropbox_unlinked_because_suspended` | `services/third-party-datastore/app/js/QueueWorker.mjs:20-25`, `:46-58` (notre synchronisation Dropbox) |

`NotificationsBuilder.mjs` construit aussi des clés pour les invitations de groupe, les affiliations institutionnelles, les abonnements et les anciens projets de débogage. Leurs appelants se trouvent dans le code des abonnements et des institutions, et la vérification des anciens projets de débogage ne s'exécute qu'avec `isSaas` (`services/web/app/src/Features/Project/ProjectListController.mjs:234-236`).

#### Qui la lit

| Code | Ce qu'il fait |
| - | - |
| `Notifications.js:4-10` (`getUserNotifications`) | `GET /user/:user_id` (`app.ts:30`). Renvoie uniquement les documents de l'utilisateur qui ont encore une `templateKey`. |
| `services/web/app/src/Features/Project/ProjectListController.mjs:367` | Charge les avis du tableau de bord des projets. |
| `services/web/app/src/Features/Notifications/NotificationsController.mjs` | `GET /notifications`, `DELETE /notifications/:notificationId` et `GET /user/notification/:notificationId` (`services/web/app/src/router.mjs:922-937`). |
| `services/web/modules/dropbox/app/src/DropboxHandler.mjs:128-131` | Notre module Dropbox : lorsqu'un utilisateur associe à nouveau Dropbox, il marque `dropbox-unlinked` et `dropboxDuplicateProjectNames-<userId>` comme lus. |

#### Index

| Nom | Clés | Options | Migration |
| - | - | - | - |
| `expires_1` | `{ expires: 1 }` | TTL, `expireAfterSeconds: 10` | `tools/migrations/20190912145014_create_notifications_indexes.mjs` |
| `key_1` | `{ key: 1 }` | | idem |
| `user_id_1` | `{ user_id: 1 }` | | idem |

#### Remarques

* Un avis lu n'est pas supprimé : seule `templateKey` disparaît. Comme le document contient toujours la clé, un `addNotification` ultérieur sans `forceCreate` pour la même clé ne fait rien (`Notifications.js:21-24`).
* Les routes `/key/:key` agissent sur la seule clé, pour tous les utilisateurs (`Notifications.js:76-100`).
* Si `web` n'a pas d'`apis.notifications.url`, il ne crée ni ne lit d'avis (`NotificationsHandler.mjs:17`, `:41`).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.