Skip to content

feat: implement soft delete and archived status for deliveries#72

Open
jerryjuche wants to merge 1 commit into
SwiftChainn:mainfrom
jerryjuche:feat/soft-delete-delivery
Open

feat: implement soft delete and archived status for deliveries#72
jerryjuche wants to merge 1 commit into
SwiftChainn:mainfrom
jerryjuche:feat/soft-delete-delivery

Conversation

@jerryjuche

Copy link
Copy Markdown

Closes #21

Summary

Implements soft-delete logic and archived status for Deliveries (Closes #21).

What changed

  • Model (src/models/Delivery.ts): Added isDeleted, deletedAt, deletedBy fields to schema. Pre-find/countDocuments middleware auto-filters soft-deleted docs (bypassable via .setOptions({ includeDeleted: true })). Instance methods softDelete() and restore().
  • Service (src/services/delivery.service.ts): Full CRUD plus archive(), restore(), listArchived() — all queries respect the soft-delete filter naturally.
  • Controller (src/controllers/delivery.controller.ts): Thin handlers wrapping the service with proper HTTP status codes and error forwarding.
  • Routes (src/routes/delivery.routes.ts): POST /, GET /, GET /:id, PATCH /:id, PATCH /:id/archive, PATCH /:id/restore, GET /archived.
  • Error handling: New AppError class in src/utils/AppError.ts replaces inline as any casts.
  • Env fix: Added dotenv.config() to server.ts (was missing).
  • Tests: 22 tests covering success, duplicate, validation, pagination, filtering, search, not-found, already-archived, not-archived, archive/restore lifecycle, and archived query endpoints.

Acceptance criteria checklist

  • isDeleted flag on Delivery schema
  • Queries auto-filter soft-deleted documents
  • Archive endpoint (PATCH /:id/archive)
  • Controller → Service → Model layered architecture
  • API versioned at /api/v1/
  • Strong TypeScript strict mode typing
  • Robust error handling with AppError + global error handler
  • 22 tests passing (Jest + mongodb-memory-server)
  • tsc --noEmit passes clean
  • eslint . --ext .ts passes with 0 errors, 0 warnings

Test results

PASS tests/delivery.test.ts (5.3 s)
Tests:       22 passed, 22 total

Follow-ups

  • Auth middleware integration (the archive endpoint accepts an optional userId but there's no auth guard yet — auth was out of scope for this issue)
  • Zod validation middleware for request bodies

Security note

The userId in the archive endpoint is extracted from req.user (set by auth middleware) but gracefully handles undefined if no auth middleware is in place yet.

@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@jerryjuche 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.

Backend: Implement soft delete logic and archived status for Deliveries

1 participant