Add actionable push notifications and fix recurring task completion

Features:
- Add task action buttons to push notifications (complete, view, cancel, etc.)
- Add button types logic for different task states (overdue, in_progress, etc.)
- Implement Chain of Responsibility pattern for task categorization
- Add comprehensive kanban categorization documentation

Fixes:
- Reset recurring task status to Pending after completion so tasks appear
  in correct kanban column (was staying in "In Progress")
- Fix PostgreSQL EXTRACT function error in overdue notifications query
- Update seed data to properly set next_due_date for recurring tasks

Admin:
- Add tasks list to residence detail page
- Fix task edit page to properly handle all fields

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-05 14:23:14 -06:00
parent bbf3999c79
commit 1b06c0639c
22 changed files with 2715 additions and 142 deletions

View File

@@ -8,6 +8,14 @@ import (
"github.com/treytartt/casera-api/internal/models"
)
// isTaskCompleted determines if a task should be considered "completed" for kanban display.
// A task is completed if next_due_date is nil (meaning it was a one-time task that's been completed).
// Recurring tasks always have a next_due_date after completion, so they're never "completed" permanently.
func isTaskCompleted(task *models.Task) bool {
// If next_due_date is nil and task has completions, it's a completed one-time task
return task.NextDueDate == nil && len(task.Completions) > 0
}
// TaskRepository handles database operations for tasks
type TaskRepository struct {
db *gorm.DB
@@ -83,8 +91,9 @@ func (r *TaskRepository) Create(task *models.Task) error {
}
// Update updates a task
// Uses Omit to exclude associations that shouldn't be updated via Save
func (r *TaskRepository) Update(task *models.Task) error {
return r.db.Save(task).Error
return r.db.Omit("Residence", "CreatedBy", "AssignedTo", "Category", "Priority", "Status", "Frequency", "ParentTask", "Completions").Save(task).Error
}
// Delete hard-deletes a task
@@ -167,8 +176,8 @@ func (r *TaskRepository) GetKanbanData(residenceID uint, daysThreshold int) (*mo
continue
}
// Check if completed (has completions)
if len(task.Completions) > 0 {
// Check if completed (one-time task with nil next_due_date)
if isTaskCompleted(&task) {
completed = append(completed, task)
continue
}
@@ -179,17 +188,28 @@ func (r *TaskRepository) GetKanbanData(residenceID uint, daysThreshold int) (*mo
continue
}
// Check due date
if task.DueDate != nil {
if task.DueDate.Before(now) {
// Use next_due_date for categorization (this handles recurring tasks properly)
if task.NextDueDate != nil {
if task.NextDueDate.Before(now) {
overdue = append(overdue, task)
} else if task.DueDate.Before(threshold) {
} else if task.NextDueDate.Before(threshold) {
dueSoon = append(dueSoon, task)
} else {
upcoming = append(upcoming, task)
}
} else {
upcoming = append(upcoming, task)
// No next_due_date and no completions - use due_date for initial categorization
if task.DueDate != nil {
if task.DueDate.Before(now) {
overdue = append(overdue, task)
} else if task.DueDate.Before(threshold) {
dueSoon = append(dueSoon, task)
} else {
upcoming = append(upcoming, task)
}
} else {
upcoming = append(upcoming, task)
}
}
}
@@ -294,8 +314,8 @@ func (r *TaskRepository) GetKanbanDataForMultipleResidences(residenceIDs []uint,
continue
}
// Check if completed (has completions)
if len(task.Completions) > 0 {
// Check if completed (one-time task with nil next_due_date)
if isTaskCompleted(&task) {
completed = append(completed, task)
continue
}
@@ -306,17 +326,28 @@ func (r *TaskRepository) GetKanbanDataForMultipleResidences(residenceIDs []uint,
continue
}
// Check due date
if task.DueDate != nil {
if task.DueDate.Before(now) {
// Use next_due_date for categorization (this handles recurring tasks properly)
if task.NextDueDate != nil {
if task.NextDueDate.Before(now) {
overdue = append(overdue, task)
} else if task.DueDate.Before(threshold) {
} else if task.NextDueDate.Before(threshold) {
dueSoon = append(dueSoon, task)
} else {
upcoming = append(upcoming, task)
}
} else {
upcoming = append(upcoming, task)
// No next_due_date and no completions - use due_date for initial categorization
if task.DueDate != nil {
if task.DueDate.Before(now) {
overdue = append(overdue, task)
} else if task.DueDate.Before(threshold) {
dueSoon = append(dueSoon, task)
} else {
upcoming = append(upcoming, task)
}
} else {
upcoming = append(upcoming, task)
}
}
}