Skip to content

[Feature]: Implement Soft Delete & Automated Trash Cleanup #179

@yash-pouranik

Description

@yash-pouranik

Description

Currently, when a developer calls the DELETE endpoint (DELETE /api/data/:collectionName/:id) in the Public API, the document is permanently deleted (Model.deleteOne()). In modern platforms, accidentally deleted data should be recoverable for a short grace period (e.g., 30 days).

We need to implement a "Soft Delete" system where documents are flagged as deleted rather than immediately removed from the database, combined with a background cron job that permanently purges old deleted documents.

Goals

  • Modify the deleteSingleDoc controller to perform a soft delete instead of a hard delete.
  • Update the API's read engine to automatically hide soft-deleted documents unless explicitly requested.
  • Build a scheduled background worker to permanently clean up the trash.

Implementation Steps

  1. Soft Delete Logic:
    • Modify apps/public-api/src/controllers/data.controller.js.
    • Change Model.deleteOne() to an update operation that sets an isDeleted: true flag and a deletedAt: Date timestamp.
  2. Read Filtering:
    • Update getAllData and getSingleDoc (and the underlying QueryEngine) to automatically append { isDeleted: { $ne: true } } to the queries.
    • (Optional) Allow developers to pass a ?include_deleted=true query parameter to fetch documents that are in the trash.
  3. Automated Cleanup Worker:
    • Create a scheduled BullMQ repeatable job (or use node-cron in a worker process) that runs once a day.
    • This worker should scan all collections and permanently run deleteMany() for documents where deletedAt is older than 30 days.

Skills Required

  • Node.js & Express
  • Mongoose / MongoDB (Queries and Schema modifications)
  • Background Jobs / CRON

Acceptance Criteria

  • Deleting a document returns success, but the document remains in the database with isDeleted: true.
  • Fetching all documents no longer returns deleted documents.
  • A background job exists that hard-deletes documents older than 30 days.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions