> ## 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.

# Notifications 컬렉션

`notifications` 은 사용자의 프로젝트 대시보드 상단에 표시되는 알림을 보관합니다. 문서 하나는 한 사용자에 대한 알림 하나이며 `key`로 식별됩니다. 컬렉션을 직접 다루는 것은 `notifications` 서비스뿐이며(`services/notifications/app/js/Notifications.js`), `web`과 `third-party-datastore`는 그 HTTP API를 호출합니다. Mongoose 스키마는 없습니다.

#### 필드

| 필드 | 타입 | 의미 | 출처 |
| - | - | - | - |
| `_id` | ObjectId | 알림 id입니다. `web`은 이 id로 알림을 읽음으로 표시합니다. | `Notifications.js:58-65` |
| `user_id` | ObjectId | 알림을 보는 사용자. | `Notifications.js:26` |
| `key` | String | 알림을 식별합니다. 예: `project-invite-<inviteId>`. upsert가 `user_id`와 `key`마다 문서 하나를 유지하며, 고유 인덱스는 없습니다. | `Notifications.js:27`, `:51-55` |
| `templateKey` | String | 프런트엔드가 렌더링할 알림입니다. 알림을 읽거나 닫으면 제거되지만 문서는 남습니다. | `Notifications.js:29`, `:63`, `:72`, `:78` |
| `messageOpts` | Object | 알림 문구에 쓰이는 값으로, `templateKey`에 따라 다릅니다(프로젝트 초대의 경우 `userName`, `projectName`, `projectId`, `token`). 사용자가 id로 알림을 닫으면 제거됩니다. | `Notifications.js:28`, `:63` |
| `expires` | Date | 선택 사항입니다. 이 시각이 지나면 TTL 인덱스가 문서를 삭제합니다. | `Notifications.js:35-50` |

#### 쓰는 코드

| 코드 | 하는 일 |
| - | - |
| `Notifications.js:20-56` (`addNotification`) | `POST /user/:user_id` (`services/notifications/app.ts:29`). `user_id` + `key`로 upsert합니다. 해당 키의 문서가 이미 있으면 호출자가 `forceCreate`를 보낼 때만 다시 기록됩니다. |
| `Notifications.js:58-65` (`removeNotificationId`) | `DELETE /user/:user_id/notification/:notification_id` (`app.ts:31-34`): `templateKey`와 `messageOpts`를 제거합니다. |
| `Notifications.js:67-80` | `DELETE /user/:user_id` 및 `DELETE /key/:key` (`app.ts:35-36`): 키로 `templateKey`를 제거합니다. |
| `Notifications.js:87-100` | `DELETE /key/:key/bulk` (`app.ts:38-41`) 는 해당 키를 가진 읽지 않은 알림을 삭제하고, `deleteNotificationByKeyOnly`는 키로 문서 하나를 삭제합니다. |
| `services/web/app/src/Features/Notifications/NotificationsHandler.mjs:33-66` | `addNotification`의 `web` 쪽입니다. 호출자가 `false`를 넘기지 않으면 `forceCreate: true`를 보냅니다. |
| `services/third-party-datastore/app/js/QueueWorker.mjs:46-58` | 우리의 Dropbox 동기화: Dropbox 계정 연결을 해제할 때 `dropbox-unlinked` 알림을 직접 게시합니다. |

CE와 우리 모듈이 만드는 알림:

| `key` | `templateKey` | 생성 위치 |
| - | - | - |
| `project-invite-<inviteId>` | `notification_project_invite`, 초대와 함께 만료 | `services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs:40-42`, 구성 위치 `services/web/app/src/Features/Notifications/NotificationsBuilder.mjs:100-122`. 초대한 이메일이 기존 사용자의 것일 때만 생성됩니다. |
| `tpdsFileLimit-<userId>` | `notification_tpds_file_limit` | `services/web/app/src/Features/ThirdPartyDataStore/TpdsController.mjs:118-124` (Dropbox 업데이트로 프로젝트가 파일 수 제한을 넘게 되는 경우), `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` 또는 `dropbox_unlinked_because_suspended` | `services/third-party-datastore/app/js/QueueWorker.mjs:20-25`, `:46-58` (우리의 Dropbox 동기화) |

`NotificationsBuilder.mjs`는 그룹 초대, 기관 소속, 구독, 오래된 디버그 프로젝트용 키도 만듭니다. 이를 호출하는 코드는 구독 및 기관 코드에 있으며, 오래된 디버그 프로젝트 검사는 `isSaas`일 때만 실행됩니다(`services/web/app/src/Features/Project/ProjectListController.mjs:234-236`).

#### 읽는 코드

| 코드 | 하는 일 |
| - | - |
| `Notifications.js:4-10` (`getUserNotifications`) | `GET /user/:user_id` (`app.ts:30`). 아직 `templateKey`가 있는 사용자 문서만 반환합니다. |
| `services/web/app/src/Features/Project/ProjectListController.mjs:367` | 프로젝트 대시보드용 알림을 불러옵니다. |
| `services/web/app/src/Features/Notifications/NotificationsController.mjs` | `GET /notifications`, `DELETE /notifications/:notificationId` 및 `GET /user/notification/:notificationId` (`services/web/app/src/router.mjs:922-937`). |
| `services/web/modules/dropbox/app/src/DropboxHandler.mjs:128-131` | 우리의 Dropbox 모듈: 사용자가 Dropbox를 다시 연결하면 `dropbox-unlinked`와 `dropboxDuplicateProjectNames-<userId>`를 읽음으로 표시합니다. |

#### 인덱스

| 이름 | 키 | 옵션 | 마이그레이션 |
| - | - | - | - |
| `expires_1` | `{ expires: 1 }` | TTL, `expireAfterSeconds: 10` | `tools/migrations/20190912145014_create_notifications_indexes.mjs` |
| `key_1` | `{ key: 1 }` | | 위와 같음 |
| `user_id_1` | `{ user_id: 1 }` | | 위와 같음 |

#### 참고

* 읽은 알림은 삭제되지 않고 `templateKey`만 사라집니다. 문서에 키가 남아 있으므로, 이후 같은 키로 `forceCreate` 없이 `addNotification`을 호출해도 아무 일도 일어나지 않습니다(`Notifications.js:21-24`).
* `/key/:key` 라우트는 사용자와 관계없이 키만으로 동작합니다(`Notifications.js:76-100`).
* `web`에 `apis.notifications.url`이 없으면 알림을 만들지도 읽지도 않습니다(`NotificationsHandler.mjs:17`, `:41`).


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