Skip to content

Latest commit

 

History

History
70 lines (57 loc) · 2.8 KB

File metadata and controls

70 lines (57 loc) · 2.8 KB

Health Tasks CRUD Implementation Summary

✅ Completed Features

Entities Created

  • HealthTask entity with TaskStatus enum (DRAFT, ACTIVE, ARCHIVED)
  • Category entity for task categorization
  • Proper TypeORM relationships and decorators

DTOs Created

  • CreateTaskDto - Validates xlmReward between 0.1 and 5.0
  • UpdateTaskDto - Extends CreateTaskDto with optional status field
  • ListTasksDto - Extends PaginationDto with category filter

Service (TasksService)

  • ✅ Uses @InjectRepository(HealthTask) with standard TypeORM Repository
  • ✅ Uses QueryBuilder directly in service for active tasks filtering
  • create() - Creates tasks with DRAFT status (ADMIN/HEALER)
  • findAll() - Returns only ACTIVE tasks with pagination and category filter
  • findOne() - Gets task by ID (public, returns any status)
  • update() - Owner or ADMIN can update; only ADMIN can publish
  • remove() - Archives task (ADMIN only via guard) - sets status to ARCHIVED

Controller (TasksController)

  • POST /tasks - @Roles(Role.ADMIN, Role.HEALER)
  • GET /tasks - Public, returns only ACTIVE tasks
  • GET /tasks/:id - Public, returns task regardless of status
  • PATCH /tasks/:id - @Roles(Role.ADMIN, Role.HEALER) - Owner or ADMIN
  • DELETE /tasks/:id - @Roles(Role.ADMIN) - Archives task

Additional Files

  • Migration file for database tables
  • Comprehensive unit tests (18 tests, all passing)
  • API documentation (HEALTH_TASKS_API.md)
  • Module registered in AppModule

✅ Acceptance Criteria Met

  1. ✅ TasksService injects @InjectRepository(HealthTask) repository
  2. ✅ GET /tasks uses QueryBuilder with WHERE status = 'ACTIVE'
  3. ✅ xlmReward validated between 0.1 and 5.0 in DTO
  4. ✅ Only admins can publish (change status to ACTIVE)
  5. ✅ GET /tasks supports pagination and category filter

✅ Code Review Fixes Applied

  1. ✅ Added @Roles(Role.ADMIN, Role.HEALER) to PATCH endpoint for consistency
  2. ✅ Removed duplicate role check in remove() - now handled by guard only
  3. ✅ Fixed repository injection - using standard TypeORM Repository pattern
  4. ✅ Moved QueryBuilder logic directly into service (removed custom repository)
  5. ✅ Updated test descriptions to match actual behavior (archive vs soft delete)
  6. ✅ Added test for findOne() returning non-ACTIVE tasks
  7. ✅ Added test for remove() when task doesn't exist

Test Results

Test Suites: 2 passed, 2 total
Tests:       18 passed, 18 total

Test Coverage

  • Service: 13 tests covering create, findAll, findOne, update, remove
  • Controller: 5 tests covering all endpoints
  • Edge cases: Non-existent tasks, non-ACTIVE status, invalid categoryId, authorization

Next Steps

  1. Run database migrations: npm run migration:run
  2. Seed categories data
  3. Test endpoints with Postman/Insomnia
  4. Consider adding e2e tests