> ## 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` lưu các thông báo hiển thị ở đầu bảng điều khiển dự án của người dùng. Mỗi tài liệu là một thông báo cho một người dùng, được xác định bằng `key`. Chỉ dịch vụ `notifications` truy cập collection này (`services/notifications/app/js/Notifications.js`); `web` và `third-party-datastore` gọi API HTTP của nó. Không có schema Mongoose.

#### Trường

| Trường | Kiểu | Ý nghĩa | Nguồn |
| - | - | - | - |
| `_id` | ObjectId | Id thông báo. `web` đánh dấu thông báo là đã đọc bằng id này. | `Notifications.js:58-65` |
| `user_id` | ObjectId | Người dùng nhìn thấy thông báo. | `Notifications.js:26` |
| `key` | String | Xác định thông báo, ví dụ `project-invite-<inviteId>`. Thao tác upsert giữ một tài liệu cho mỗi cặp `user_id` và `key`; không có chỉ mục duy nhất. | `Notifications.js:27`, `:51-55` |
| `templateKey` | String | Thông báo nào được frontend hiển thị. Bị xóa khi thông báo được đọc hoặc bỏ qua; tài liệu vẫn còn. | `Notifications.js:29`, `:63`, `:72`, `:78` |
| `messageOpts` | Object | Các giá trị cho nội dung thông báo, tùy theo `templateKey` (với lời mời vào dự án: `userName`, `projectName`, `projectId`, `token`). Bị xóa khi người dùng bỏ qua thông báo theo id. | `Notifications.js:28`, `:63` |
| `expires` | Date | Tùy chọn. Chỉ mục TTL xóa tài liệu sau thời điểm này. | `Notifications.js:35-50` |

#### Ai ghi

| Mã | Chức năng |
| - | - |
| `Notifications.js:20-56` (`addNotification`) | `POST /user/:user_id` (`services/notifications/app.ts:29`). Upsert theo `user_id` + `key`. Nếu tài liệu với khóa đó đã tồn tại, nó chỉ được ghi lại khi bên gọi gửi `forceCreate`. |
| `Notifications.js:58-65` (`removeNotificationId`) | `DELETE /user/:user_id/notification/:notification_id` (`app.ts:31-34`): xóa `templateKey` và `messageOpts`. |
| `Notifications.js:67-80` | `DELETE /user/:user_id` và `DELETE /key/:key` (`app.ts:35-36`): xóa `templateKey` theo khóa. |
| `Notifications.js:87-100` | `DELETE /key/:key/bulk` (`app.ts:38-41`) xóa các thông báo chưa đọc có một khóa; `deleteNotificationByKeyOnly` xóa một tài liệu theo khóa. |
| `services/web/app/src/Features/Notifications/NotificationsHandler.mjs:33-66` | Phía `web` của `addNotification`. Gửi `forceCreate: true` trừ khi bên gọi truyền `false`. |
| `services/third-party-datastore/app/js/QueueWorker.mjs:46-58` | Đồng bộ Dropbox của chúng tôi: khi hủy liên kết một tài khoản Dropbox, nó gửi trực tiếp thông báo `dropbox-unlinked`. |

Các thông báo do CE và các module của chúng tôi tạo:

| `key` | `templateKey` | Vị trí tạo |
| - | - | - |
| `project-invite-<inviteId>` | `notification_project_invite`, hết hạn cùng lời mời | `services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs:40-42`, được dựng tại `services/web/app/src/Features/Notifications/NotificationsBuilder.mjs:100-122`. Chỉ khi email được mời thuộc về một người dùng đã có. |
| `tpdsFileLimit-<userId>` | `notification_tpds_file_limit` | `services/web/app/src/Features/ThirdPartyDataStore/TpdsController.mjs:118-124` (một bản cập nhật từ Dropbox sẽ khiến dự án vượt quá giới hạn tệp), `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` hoặc `dropbox_unlinked_because_suspended` | `services/third-party-datastore/app/js/QueueWorker.mjs:20-25`, `:46-58` (đồng bộ Dropbox của chúng tôi) |

`NotificationsBuilder.mjs` cũng dựng khóa cho lời mời nhóm, liên kết tổ chức, gói đăng ký và các dự án gỡ lỗi cũ. Nơi gọi chúng nằm trong mã gói đăng ký và tổ chức, còn việc kiểm tra dự án gỡ lỗi cũ chỉ chạy khi `isSaas` (`services/web/app/src/Features/Project/ProjectListController.mjs:234-236`).

#### Ai đọc

| Mã | Chức năng |
| - | - |
| `Notifications.js:4-10` (`getUserNotifications`) | `GET /user/:user_id` (`app.ts:30`). Chỉ trả về các tài liệu của người dùng vẫn còn `templateKey`. |
| `services/web/app/src/Features/Project/ProjectListController.mjs:367` | Tải thông báo cho bảng điều khiển dự án. |
| `services/web/app/src/Features/Notifications/NotificationsController.mjs` | `GET /notifications`, `DELETE /notifications/:notificationId` và `GET /user/notification/:notificationId` (`services/web/app/src/router.mjs:922-937`). |
| `services/web/modules/dropbox/app/src/DropboxHandler.mjs:128-131` | Module Dropbox của chúng tôi: khi người dùng liên kết lại Dropbox, đánh dấu `dropbox-unlinked` và `dropboxDuplicateProjectNames-<userId>` là đã đọc. |

#### Chỉ mục

| Tên | Khóa | Tùy chọn | Migration |
| - | - | - | - |
| `expires_1` | `{ expires: 1 }` | TTL, `expireAfterSeconds: 10` | `tools/migrations/20190912145014_create_notifications_indexes.mjs` |
| `key_1` | `{ key: 1 }` | | như trên |
| `user_id_1` | `{ user_id: 1 }` | | như trên |

#### Ghi chú

* Thông báo đã đọc không bị xóa: chỉ `templateKey` biến mất. Vì tài liệu vẫn giữ khóa, một lệnh `addNotification` sau đó không có `forceCreate` cho cùng khóa sẽ không làm gì (`Notifications.js:21-24`).
* Các route `/key/:key` chỉ tác động theo khóa, trên mọi người dùng (`Notifications.js:76-100`).
* Nếu `web` không có `apis.notifications.url`, nó không tạo cũng không đọc thông báo (`NotificationsHandler.mjs:17`, `:41`).


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