diff options
Diffstat (limited to 'internal/store/chains.go')
| -rw-r--r-- | internal/store/chains.go | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/internal/store/chains.go b/internal/store/chains.go index 4f51b3c..f3bd0d7 100644 --- a/internal/store/chains.go +++ b/internal/store/chains.go @@ -16,11 +16,11 @@ const defaultChainProjectColor = "#8B5CF6" // CreateChain creates a backing project (per the design's "a chain is // effectively a project with strict sequential unlocking"), a task_chains -// row, and one native_tasks row per title in taskTitles. Position 0 is -// created unlocked with due_date = now; the rest are locked with no due -// date. All in one transaction so a partial chain never exists. -func (s *Store) CreateChain(name string, taskTitles []string) (*models.Chain, error) { - if len(taskTitles) == 0 { +// row, and one native_tasks row per entry in tasks. Position 0 is created +// unlocked with due_date = now; the rest are locked with no due date. All +// in one transaction so a partial chain never exists. +func (s *Store) CreateChain(name string, tasks []models.ChainTaskInput) (*models.Chain, error) { + if len(tasks) == 0 { return nil, fmt.Errorf("chain must have at least one task") } @@ -44,16 +44,20 @@ func (s *Store) CreateChain(name string, taskTitles []string) (*models.Chain, er return nil, err } - for i, title := range taskTitles { + for i, t := range tasks { unlocked := i == 0 var dueDate *time.Time if unlocked { dueDate = &now } + priority := t.Priority + if priority == 0 { + priority = 1 + } if _, err := tx.Exec(` - INSERT INTO native_tasks (id, content, project_name, project_id, priority, due_date, chain_id, chain_position, chain_unlocked, created_at, updated_at) - VALUES (?, ?, ?, ?, 1, ?, ?, ?, ?, ?, ?) - `, newTaskID(), title, project.Name, project.ID, dueDate, chainID, i, unlocked, now, now); err != nil { + INSERT INTO native_tasks (id, content, description, project_name, project_id, priority, due_date, chain_id, chain_position, chain_unlocked, created_at, updated_at) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + `, newTaskID(), t.Content, t.Description, project.Name, project.ID, priority, dueDate, chainID, i, unlocked, now, now); err != nil { return nil, err } } |
