Duplicate Reviewed Flag Middleware
Component Detail
Description
Lightweight interceptor layer that injects the duplicate_reviewed field into the activity insert payload based on user resolution decisions. Ensures the flag is consistently set regardless of which submission path (single wizard, bulk proxy, or coordinator) triggers the final database write.
duplicate-reviewed-flag-middleware
Summaries
The Duplicate Reviewed Flag Middleware ensures that every activity record written to the database carries a consistent, accurate audit marker indicating whether it was reviewed for duplicates before submission. This seemingly simple flag has significant operational value: it allows coordinators to instantly identify records that bypassed duplicate review versus those that were explicitly approved despite a match, supporting both routine data quality checks and audit responses. As a shared component used across all submission paths — individual wizard, bulk proxy, and coordinator resolution — it guarantees uniform flag behaviour regardless of how an activity enters the system, reducing the risk of compliance gaps or inconsistent data that could affect funder reporting.
The Duplicate Reviewed Flag Middleware is a low-complexity shared component that operates across three distinct submission paths: the activity wizard, bulk proxy submissions, and coordinator-level resolution. Because it is shared, changes to this middleware affect all three paths simultaneously, making regression testing across all submission flows mandatory whenever the middleware is modified. The component has no declared dependencies on other custom components, making it an early, independent deliverable that can be built and unit tested before the submission paths are fully integrated. Delivery risk is low, but integration testing must confirm consistent flag behaviour across all three callers.
Documentation of the default flag values and the conditions that trigger each should be produced early to align all consuming teams.
The Duplicate Reviewed Flag Middleware is a lightweight interceptor with three interfaces: applyReviewedFlag() which injects duplicate_reviewed: true or false into an activity payload based on the wasReviewed boolean argument; getDefaultPayloadFlags() which returns the default flag state for normal unreviewed submissions (duplicate_reviewed: false); and validateFlagConsistency() which asserts the payload contains a valid, non-null duplicate_reviewed value before the write is executed. It carries no dependencies and holds no local state — all logic is stateless and deterministic. As a shared component, it must be called by the activity wizard, bulk submission handler, and coordinator resolution flow before any database write. The middleware should be implemented as a pure utility class or function set to maximise testability.
Unit tests should cover all three callers explicitly and verify that the flag cannot be omitted or set to an invalid type through any submission path.
Responsibilities
- Inject duplicate_reviewed: true into payload when user selects 'proceed' after warning
- Ensure duplicate_reviewed defaults to false for all normal unreviewed submissions
- Provide consistent flag handling across activity wizard, bulk, and proxy submission paths
Interfaces
applyReviewedFlag(payload, wasReviewed)
getDefaultPayloadFlags()
validateFlagConsistency(payload)