Scope lead notes by project and share them with task agents

This commit is contained in:
Ian Gulliver
2026-10-16 23:12:14 -07:00
parent 165266f25d
commit 35184dc081
13 changed files with 395 additions and 251 deletions
+14 -7
View File
@@ -11,7 +11,7 @@ import (
)
func (s *Store) LeadNotes(ctx context.Context, owner string) ([]api.LeadNote, error) {
rows, err := s.db.QueryContext(ctx, `SELECT id, text, created_at, updated_at FROM lead_notes WHERE owner = ? ORDER BY created_at, id`, owner)
rows, err := s.db.QueryContext(ctx, `SELECT id, text, project_id, created_at, updated_at FROM lead_notes WHERE owner = ? ORDER BY created_at, id`, owner)
if err != nil {
return nil, err
}
@@ -20,12 +20,16 @@ func (s *Store) LeadNotes(ctx context.Context, owner string) ([]api.LeadNote, er
notes := []api.LeadNote{}
for rows.Next() {
n := api.LeadNote{}
projectID := ""
createdAt := ""
updatedAt := ""
err = rows.Scan(&n.Id, &n.Text, &createdAt, &updatedAt)
err = rows.Scan(&n.Id, &n.Text, &projectID, &createdAt, &updatedAt)
if err != nil {
return nil, err
}
if projectID != "" {
n.ProjectId = &projectID
}
n.CreatedAt, err = parseTime(createdAt)
if err != nil {
return nil, err
@@ -39,21 +43,24 @@ func (s *Store) LeadNotes(ctx context.Context, owner string) ([]api.LeadNote, er
return notes, rows.Err()
}
func (s *Store) SaveLeadNote(ctx context.Context, owner, id, text, actor string) (api.LeadNote, error) {
func (s *Store) SaveLeadNote(ctx context.Context, owner, id, projectID, text, actor string) (api.LeadNote, error) {
at := time.Now().UTC()
n := api.LeadNote{Id: id, Text: text, CreatedAt: at, UpdatedAt: at}
if projectID != "" {
n.ProjectId = &projectID
}
err := s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
if id == "" {
n.Id = NewID()
_, err := tx.ExecContext(ctx, `INSERT INTO lead_notes (id, owner, text, created_at, updated_at) VALUES (?, ?, ?, ?, ?)`,
n.Id, owner, text, formatTime(at), formatTime(at))
_, err := tx.ExecContext(ctx, `INSERT INTO lead_notes (id, owner, text, project_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)`,
n.Id, owner, text, projectID, formatTime(at), formatTime(at))
if err != nil {
return err
}
} else {
createdAt := ""
err := tx.QueryRowContext(ctx, `UPDATE lead_notes SET text = ?, updated_at = ? WHERE id = ? AND owner = ? RETURNING created_at`,
text, formatTime(at), id, owner).Scan(&createdAt)
err := tx.QueryRowContext(ctx, `UPDATE lead_notes SET text = ?, project_id = ?, updated_at = ? WHERE id = ? AND owner = ? RETURNING created_at`,
text, projectID, formatTime(at), id, owner).Scan(&createdAt)
if errors.Is(err, sql.ErrNoRows) {
return fmt.Errorf("note %s: %w", id, ErrNotFound)
}