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

@@ -73,8 +73,9 @@ func (r *ContractorRepository) Create(contractor *models.Contractor) error {
}
// Update updates a contractor
// Uses Omit to exclude associations that could interfere with Save
func (r *ContractorRepository) Update(contractor *models.Contractor) error {
return r.db.Save(contractor).Error
return r.db.Omit("CreatedBy", "Specialties", "Tasks", "Residence").Save(contractor).Error
}
// Delete soft-deletes a contractor

View File

@@ -90,8 +90,9 @@ func (r *DocumentRepository) Create(document *models.Document) error {
}
// Update updates a document
// Uses Omit to exclude associations that could interfere with Save
func (r *DocumentRepository) Update(document *models.Document) error {
return r.db.Save(document).Error
return r.db.Omit("CreatedBy", "Task", "Images", "Residence").Save(document).Error
}
// Delete soft-deletes a document

View File

@@ -89,8 +89,9 @@ func (r *ResidenceRepository) Create(residence *models.Residence) error {
}
// Update updates a residence
// Uses Omit to exclude associations that could interfere with Save
func (r *ResidenceRepository) Update(residence *models.Residence) error {
return r.db.Save(residence).Error
return r.db.Omit("Owner", "Users", "PropertyType").Save(residence).Error
}
// Delete soft-deletes a residence by setting is_active to false

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)
}
}
}

View File

@@ -384,8 +384,8 @@ func TestKanbanBoard_CompletedTasksGoToCompletedColumn(t *testing.T) {
assert.Len(t, completedColumn.Tasks, 1)
assert.Equal(t, "Completed Task", completedColumn.Tasks[0].Title)
// Verify button types for completed column (view only)
assert.ElementsMatch(t, []string{"view"}, completedColumn.ButtonTypes)
// Verify button types for completed column (read-only, no buttons)
assert.ElementsMatch(t, []string{}, completedColumn.ButtonTypes)
}
func TestKanbanBoard_InProgressTasksGoToInProgressColumn(t *testing.T) {
@@ -773,7 +773,7 @@ func TestKanbanBoard_ColumnMetadata(t *testing.T) {
{"in_progress_tasks", "In Progress", "#5856D6", []string{"edit", "complete", "cancel"}, "hammer", "Build"},
{"due_soon_tasks", "Due Soon", "#FF9500", []string{"edit", "complete", "cancel", "mark_in_progress"}, "clock", "Schedule"},
{"upcoming_tasks", "Upcoming", "#007AFF", []string{"edit", "complete", "cancel", "mark_in_progress"}, "calendar", "Event"},
{"completed_tasks", "Completed", "#34C759", []string{"view"}, "checkmark.circle", "CheckCircle"},
{"completed_tasks", "Completed", "#34C759", []string{}, "checkmark.circle", "CheckCircle"}, // Completed tasks are read-only (no buttons)
{"cancelled_tasks", "Cancelled", "#8E8E93", []string{"uncancel", "delete"}, "xmark.circle", "Cancel"},
}