Skip to content

Tasks API

Complete API reference for managing tasks in BlockForge.

Overview

Tasks are integrated with pages and workspaces. Each task has:

  • Title and description
  • Status (active, completed)
  • Priority (high, medium, low)
  • Due date
  • Associated page (optional)

List Tasks

Get all tasks in a workspace:

javascript
const { data, error } = await supabase
  .from('tasks')
  .select('*')
  .eq('workspace_id', workspaceId)
  .order('due_date', { ascending: true })

Filter Tasks

javascript
// By status
const { data } = await supabase
  .from('tasks')
  .select('*')
  .eq('workspace_id', workspaceId)
  .eq('completed', false)

// By priority
const { data } = await supabase
  .from('tasks')
  .select('*')
  .eq('workspace_id', workspaceId)
  .eq('priority', 'high')

// By due date
const { data } = await supabase
  .from('tasks')
  .select('*')
  .eq('workspace_id', workspaceId)
  .gte('due_date', new Date().toISOString())

Get Task

Get a single task by ID:

javascript
const { data, error } = await supabase
  .from('tasks')
  .select('*')
  .eq('id', taskId)
  .single()

Create Task

Create a new task:

javascript
const { data, error } = await supabase
  .from('tasks')
  .insert([
    {
      title: 'Complete documentation',
      workspace_id: workspaceId,
      page_id: pageId, // optional
      priority: 'high',
      due_date: '2024-12-31',
      completed: false
    }
  ])
  .select()

Update Task

Update task properties:

javascript
const { data, error } = await supabase
  .from('tasks')
  .update({
    title: 'Updated task title',
    completed: true,
    priority: 'medium'
  })
  .eq('id', taskId)

Mark as Completed

javascript
const { data, error } = await supabase
  .from('tasks')
  .update({ completed: true })
  .eq('id', taskId)

Delete Task

Delete a task:

javascript
const { error } = await supabase
  .from('tasks')
  .delete()
  .eq('id', taskId)

Task Schema

typescript
interface Task {
  id: string
  title: string
  description?: string
  workspace_id: string
  page_id?: string
  priority: 'high' | 'medium' | 'low'
  due_date?: string
  completed: boolean
  created_at: string
  updated_at: string
  created_by: string
}

Realtime Updates

Subscribe to task changes:

javascript
const subscription = supabase
  .channel('tasks-changes')
  .on('postgres_changes', 
    {
      event: '*',
      schema: 'public',
      table: 'tasks',
      filter: `workspace_id=eq.${workspaceId}`
    },
    (payload) => {
      console.log('Task change:', payload)
    }
  )
  .subscribe()

Next Steps

Built with ❤️ for BlockForge