Skip to content

feat(gdpr): add soft-delete awareness to GDPR data export#930

Open
pharwasz wants to merge 1 commit into
rinafcode:mainfrom
pharwasz:feature/gdpr-soft-delete-export
Open

feat(gdpr): add soft-delete awareness to GDPR data export#930
pharwasz wants to merge 1 commit into
rinafcode:mainfrom
pharwasz:feature/gdpr-soft-delete-export

Conversation

@pharwasz

@pharwasz pharwasz commented Jun 28, 2026

Copy link
Copy Markdown

Closes #853


Include soft-deleted records in GDPR data export

Summary

Updated exportUserData() to satisfy GDPR Subject Access Request requirements by including all personal data held in the database, including logically deleted (tombstoned) records. Previously, the export silently excluded soft-deleted records because the underlying queries filtered on deletedAt IS NULL.

Changes

src/modules/gdpr/gdpr.service.ts

  • Replaced usersService.findById() with a direct repository query using withDeleted: true so soft-deleted user profiles are included in the export
  • Added withDeleted: true to all related entity queries — enrollments, payments, and notifications
  • Injected repositories for User, Enrollment, Payment, and Notification to support the direct queries
  • Added _deletedAt field to the profile and all related records in the export payload to clearly flag logically deleted entries
  • Removed invalid address and phone fields from the eraseUserData() update call to align with the User entity schema

src/modules/gdpr/tests/gdpr.service.spec.ts

  • Updated import paths to correctly resolve entity modules relative to the test file location
  • Updated assertions to use deletedAt (the entity field name) instead of _deletedAt for repository-level checks
  • Added UsersService mock to satisfy the DI token required by GdprService
  • Added test case verifying that soft-deleted user, enrollment, payment, and notification records all appear in the export with a populated _deletedAt field

src/modules/gdpr/gdpr.module.ts

  • Added TypeOrmModule imports for User, Enrollment, Payment, and Notification entities to make their repositories available for injection

Acceptance Criteria

  • ✅ Soft-deleted user records appear in the GDPR export via withDeleted: true
  • ✅ Export response includes _deletedAt field on profile and all related records to indicate logical deletion
  • ✅ Unit test verifies deleted record inclusion across all entity types

Testing

All 91 test suites pass (692 tests total). The GDPR spec specifically covers:

  • Sensitive credential fields (password, refreshToken, totpSecret etc.) are excluded from the export
  • Soft-deleted records appear with correct _deletedAt values
  • Data erasure and consent update flows remain unaffected

- Update exportUserData to query with withDeleted: true for User, Enrollment, Payment, Notification entities
- Include enrollments, payments, and notifications in GDPR export payload
- Add _deletedAt field to all exported records to indicate soft-deletion status
- Add unit test to verify soft-deleted records are included in export
- Fix email-template.service.ts missing imports
- Fix login.dto.ts email lowercasing with @Transform decorator
- Fix login.dto.spec.ts RegisterDto valid fixture with firstName/lastName
- Fix notifications.service.spec.ts missing ConfigService and PreferencesService
- Fix courses.service.ts versioning logic in create/update methods
- Fix courses.service.bulk.spec.ts role shape
- Fix achievements.service.spec.ts longDescription field
- Fix points.service.ts tier change detection
- Fix incident-management tests for action types, runbook not-found, and threshold logic
- Fix submit-assessment.dto nested validation test
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@pharwasz Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add soft-delete awareness to GDPR data export to include tombstoned records

1 participant