backend answer module complete

πŸ“… 26 Jul 2025

View on Github β†—

date: 2025-07-26 topics: [nodejs, backend, devflow, testing, dsa] day: 10

πŸ“˜ Day 10 – Answer Module: DONE & DUSTED πŸ’₯

βœ… What I Worked On

πŸ”¨ Goal: Wrap up the Answer module in DevFlow
And that’s exactly what I did πŸ‘‡

TaskStatus
βž• Pending Service/Controller logicβœ… Completed
πŸ”’ Ownership checks for delete/updateβœ… Secured
πŸ“„ Finalized route-level documentationβœ… Documented
πŸ§ͺ Unit tests for service/controllerβœ… Added
πŸ“˜ DSA revision: Sorting techniquesβœ… Reviewed

🧠 Backend Highlights

βœ… Service & Controller Logic

  • Finished all remaining routes: create, update, getById, getAllByQuestion
  • Services structured to return clean, validated responses

πŸ”’ Ownership Checks (Security)

  • Only authors can update or delete their answers:
if (answer.userId !== req.user.id) {
  throw new UnauthorizedError("Access denied");
}

Clean separation of logic: controller handles request, service enforces rules

πŸ“„ Route Documentation

  • All routes now follow Swagger/JSDoc style:
/**
 * @route   PUT /api/v1/answers/:id
 * @desc    Update an answer
 * @access  Private
 */

πŸ§ͺ Unit Testing Added

  • Service layer covered with basic tests:

    • Create
    • Update with wrong user
    • Delete with ownership
    • Edge cases (e.g., non-existent answer)

πŸ“˜ DSA Review – Sorting Techniques

  • πŸ” Bubble Sort (swap until sorted)
  • πŸ”’ Selection Sort (min each pass)
  • πŸͺœ Insertion Sort (place where it fits)
  • 🧠 Compared time complexity and stability

❌ Blockers

  • Needed some tweaks to mock Mongoose methods in unit tests
  • Minor bugs in middleware chaining for auth + validation (now resolved)

🧠 Reflection

This wasn’t just β€œfinish the module.” It was about doing it right: clean code, secure access, test coverage, and docs.

Feeling confident in the structure of DevFlow’s backend now!

πŸ“Έ Progress Snapshot

Answer Module Complete

πŸ”— References / Code