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
- 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.
- 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.
- 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
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
deleteSingleDoccontroller to perform a soft delete instead of a hard delete.Implementation Steps
apps/public-api/src/controllers/data.controller.js.Model.deleteOne()to an update operation that sets anisDeleted: trueflag and adeletedAt: Datetimestamp.getAllDataandgetSingleDoc(and the underlyingQueryEngine) to automatically append{ isDeleted: { $ne: true } }to the queries.?include_deleted=truequery parameter to fetch documents that are in the trash.node-cronin a worker process) that runs once a day.deleteMany()for documents wheredeletedAtis older than 30 days.Skills Required
Acceptance Criteria
isDeleted: true.