Technical Reference
Tasks

Tasks — Technical Reference

This page covers the data models, completion lifecycle, and daily digest architecture behind the Tasks feature.

Data Models

tasks

ColumnTypeDescription
iduuidPrimary key
workspace_iduuidFK → workspaces.id — tenant isolation (ON DELETE CASCADE)
titletextRequired. Short description of the action item
descriptiontextOptional detailed notes (defaults to empty string)
due_datetimestamptzWhen the task is due. Drives the dashboard widget and daily digest
statustext'open' or 'completed' (CHECK constraint)
contact_iduuidFK → contacts.id (ON DELETE SET NULL) — optional contact link
deal_iduuidFK → deals.id (ON DELETE SET NULL) — optional deal link
assigned_touuidFK → user_profiles.id — assigned workspace member
completed_attimestamptzTimestamp when marked as completed (NULL if open)
reminder_sent_attimestamptzUsed by the daily digest to prevent duplicate notifications
created_byuuidFK → user_profiles.id — who created the task
created_attimestamptzWhen the task was created
updated_attimestamptzWhen the task was last modified

Soft links: Contact and deal FKs use ON DELETE SET NULL — if the linked contact or deal is deleted, the task survives as a general to-do item.

Architecture

Completion Lifecycle

ActionField Changes
Completestatus'completed', completed_at → current timestamp
Reopenstatus'open', completed_at → NULL, reminder_sent_at → NULL

Clearing reminder_sent_at on reopen ensures the task re-enters the daily digest cycle.

Task List Sorting

ViewSort Order
Open tasksdue_date ASC (overdue first, soonest due next, no due date last). Secondary: created_at DESC
Completed taskscompleted_at DESC (most recently completed first)

Cascading Contact / Deal Pickers

The task creation form implements intelligent cascading between the contact and deal dropdowns:

  1. Selecting a deal → auto-fills contact_id with the deal's linked contact
  2. Selecting a contact → filters the deal dropdown to only show that contact's deals
  3. Changing the contact → clears any incompatible deal_id selection

When creating from a Contact Detail page, contact_id is pre-filled. When creating from a Deal Detail page, both deal_id and contact_id are pre-filled.

Deep Linking

Tasks support URL-based deep linking: /tasks?taskId=<id> automatically opens the task detail view. This is used by Global Search to jump directly to a task from search results.

Completed Today Section

The "Completed Today" section displays tasks completed within the current day. Tasks are rendered with strikethrough text and reduced opacity. The section respects the active assignee filter — filtering to "My Tasks" shows only your completed tasks.

Present on four surfaces: /tasks page, dashboard widget, Contact Detail, Deal Detail.

Daily Digest Architecture

Cron Configuration

PropertyValue
ScheduleDaily at 8:00 AM US Central (1:00 PM UTC)
Cron expression0 13 * * *
Endpoint/api/cron/task-digest
AuthenticationAuthorization: Bearer {CRON_SECRET}
Email typeTransactional (system notification)
SenderPLATFORM_SENDER_EMAIL
{
    "path": "/api/cron/task-digest",
    "schedule": "0 13 * * *"
}

Digest Pipeline

  1. Authenticate — Verify CRON_SECRET bearer token
  2. Fetch eligible tasks — Query: status = 'open', assigned_to IS NOT NULL, due_date ≤ end of today, reminder_sent_at is NULL or before today
  3. Filter already-reminded — Exclude tasks where reminder_sent_at matches today
  4. Group by user — Each user receives one email regardless of task count
  5. Build digest — Resolve user email via auth.admin.getUserById(), classify tasks into "Due Today" and "Overdue", build HTML email
  6. Send and stamp — Send via Resend, stamp reminder_sent_at on all included tasks

Deduplication Logic

The reminder_sent_at field prevents duplicate emails within the same day. Overdue tasks re-appear in the next day's digest because their reminder_sent_at will be yesterday's date. Reopened tasks have reminder_sent_at cleared, so they immediately re-enter the digest cycle.

Email Template

SectionStyle
HeaderGreen gradient (#059669 → #10b981), "Gordon CRM — Task Digest"
GreetingPersonalized: "Good morning, {first_name}!"
OverdueRed heading (⚠️), red border, task title + contact/deal + original due date
Due TodayStandard heading (📋), task title + contact/deal
CTAGreen button → /tasks
Footer"This is an automated notification from Gordon CRM."

Related Cron Jobs

Cron JobSchedulePurpose
Campaign SweeperEvery 5 minutesProcess due campaign enrollments
Broadcast SweeperEvery 5 minutesProcess scheduled broadcasts
Birthday SweeperDaily at 8:00 AM UTCFire birthday automation triggers
Task DigestDaily at 1:00 PM UTCSend daily task summary emails

Automation Integration

The create_task automation action creates a task pre-linked to the triggering contact with configurable fields:

  • title — Task title (supports template variables)
  • description — Optional description
  • assigned_to — Workspace member to assign
  • due_date_offset — Number of days from trigger to set the due date

See Automations → Actions for the full specification.

Security

RLS Policies

OperationPolicy
SELECTAll workspace members can view tasks
INSERTAll workspace members can create tasks
UPDATEAll workspace members can edit tasks
DELETEAdmin or Owner only