Scope lead notes by project and share them with task agents
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -462,6 +462,8 @@ ALTER TABLE tasks ADD COLUMN merge_after_review_id TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE tasks ADD COLUMN merge_after_review_target TEXT NOT NULL DEFAULT '';
|
||||
`}, {"add-inbox-response-images", `
|
||||
ALTER TABLE inbox_responses ADD COLUMN images TEXT NOT NULL DEFAULT '[]';
|
||||
`}, {"add-lead-note-projects", `
|
||||
ALTER TABLE lead_notes ADD COLUMN project_id TEXT NOT NULL DEFAULT '';
|
||||
`}}
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user