# Tasks

## 1. Review and database

- [x] 1.1 Record user decisions on F1–F3, D1 and P1–P3 from design.md before affected implementation; verify approval references are documented and revise artifacts if any proposal is rejected.
- [x] 1.2 After D1 approval, update prisma/models/Notification.prisma with nullable unique eventKey, assemble schema and update schema-design.md; verify model/schema/ERD consistency and Prisma validation.
- [x] 1.3 Create and inspect the additive migration with Prisma CLI, apply it to the authorized development database and generate client; verify migration status, preserved existing records and concurrent duplicate-key rejection.

## 2. Personal inbox API

- [x] 2.1 Add notifications validators, service, controller and authenticated routes following existing conventions; verify list/detail/summary, response envelopes, active session enforcement and cross-user 404 tests.
- [x] 2.2 Implement stable filtering, pagination, category/reference DTO mapping and calibration exclusions; verify tied timestamps, one-sided/date-boundary ranges, invalid dates and out-of-range pages.
- [x] 2.3 Implement read/read-all, personal delete and restore; verify first-read timestamp, server cutoff, retries, other-recipient isolation and read state preserved after undo.
- [x] 2.4 Implement filtered CSV export; verify all pages, ownership, quoting, formula protection, timezone and explicit 10,000-row cap behavior.
- [x] 2.5 Add notifications.openapi.ts and endpoint usage documentation; verify documentation registration and documented contracts against API tests.

## 3. Event generation

- [x] 3.1 Add transactional publisher with eventKey and active-role recipient resolution; verify concurrent duplicate suppression, complete recipient creation, rollback and no resurrection of deleted entries.
- [x] 3.2 Integrate pending checkout and urgent WO events across manual, accepted-report and quarantine creation/update paths; verify auto-approved checkout exclusion, both maintenance targets and one urgent event per WO.
- [x] 3.3 Integrate low-stock checks into inventory ledger, direct checkout approval balance updates and threshold edits; verify quarantine availability, reversals, zero minimum and one alert per part/local date.
- [x] 3.4 Add bounded repeatable reminder-check CLI for generated PM, overdue WO and persistent low stock; verify concurrent runs, terminal-state races, timezone boundaries and calibration exclusion.
- [x] 3.5 Document recipient matrix, repetition policy, inactive preferences and explicit scheduler setup/rollback; verify command smoke run produces structured counts and does not replay historical urgent/approval events.

## 4. Frontend consumers

- [x] 4.1 After approved frontend scope, add notifications.service.ts and user-scoped React Query hooks using existing HTTP conventions; verify API errors, abort handling, query keys, invalidation and account-change cache isolation.
- [x] 4.2 Connect Notifications page and existing detail/filter/table/actions to API, replacing dummy state and simulation footer; verify read-all/export scope, delete/undo, pagination after deletion and loading/error/empty feedback.
- [x] 4.3 Connect top-header.tsx to the same feed with pageSize3 and unread summary; verify 0/1/3/more-than-3 cases, newest ordering including read entries and no acknowledgement merely on opening.
- [x] 4.4 Apply approved F3 navigation from Lihat semua and individual previews to the existing Notifications page/detail; verify direct navigation, missing/deleted detail handling and preservation of unrelated header controls.
- [x] 4.5 Enable approved visible-session polling and focus refresh; verify both consumers synchronize after mutations and polling stops for anonymous sessions/hidden tabs.

## 5. Integration verification

- [x] 5.1 Exercise pending public checkout, urgent quarantine WO, low stock and scheduled reminder through API to page/header; verify correct recipients and persisted read/delete/restore state across reloads.
- [x] 5.2 Run affected API tests, frontend type/build checks and OpenSpec strict validation; document results and confirm calibration/Settings/email/new business-action UI have not entered the implementation scope.
