This PR completes the implementation of the user confessions endpoint, transitioning it from a mock placeholder to a fully functional database-backed feature. It enables users to retrieve their own anonymous confessions with support for standard cursor-based pagination, stable sorting, and filtering.
- Strict Ownership: Users are restricted to fetching only their own confessions using their JWT identity.
- Admin Access: Users with the
ADMINrole are authorized to fetch confessions for any user ID for moderation purposes. - Content Decryption: Confession messages are decrypted using the system
aesKeybefore being returned to the client, ensuring the data is readable for the owner.
- Cursor Pagination: Implemented stable cursor-based pagination using the system-wide
CursorPaginatedResponseDto. - Filtering: Added support for filtering by
moderationStatus(e.g., approved, pending) andgender. - Sorting: Supports
NEWESTandTRENDINGsorting orders.
- Identity Resolution: Added logic to resolve all anonymous identities linked to a specific user account.
- Entity Update: Exposed
anonymousUserIdin theAnonymousConfessionentity to improve query performance and simplify the relation bridging. - DI Resolution: Fixed a circular dependency between
UserModuleandConfessionModuleusingforwardRef.
- Unit Tests: Updated
ConfessionServiceunit tests to cover identity resolution and query building. - E2E Tests: Added
test/user-confessions.e2e-spec.tscovering:- Successful pagination.
- Status filtering.
- Unauthorized access prevention (403 Forbidden).
- Empty state handling.
- Verified successful build with
npm run build. - Manually audited the TypeORM QueryBuilder output for efficient index usage.
#723