Comments

Comments provide a discussion thread on prestarts. Any project member can add comments, making it easy to communicate about safety concerns, equipment status, or shift handover notes.

Add Comment

  1. User types in the comment input at the bottom of the Comments tab
  2. Clicks “Post” (disabled when empty or while submitting)
  3. Calls createComment(orgId, projectId, prestartId, content)
  4. Go handler inserts into comments with user_id from session
  5. TanStack Query invalidation refreshes the comment list

Delete Comment

  1. User clicks “Delete” on their own comment (or any comment if admin)
  2. Confirmation dialog
  3. Calls deleteComment(orgId, projectId, prestartId, commentId)
  4. Go handler sets deleted_at = NOW() (soft delete)
  5. Author-only check: non-admin users can only delete their own comments

Comment Display

Each comment shows:

  • User name — from JOIN with users table
  • Timestamp — when it was posted, in the project’s time zone
  • Content — the comment text
  • Delete button — visible for comment author and admins

Real-Time Updates

Comment changes fire LISTEN/NOTIFY via the notify_comment_change trigger on the shared comments table. That table is polymorphic — the same thread serves prestarts, diaries and issues — so the payload carries table, action, org_id, project_id, entity_type and entity_id. The project_id is denormalized for zero-cost trigger execution.

Prestart comments invalidate project-wide, as they always have:

  • ["prestart-comments", orgId, projectId] — refreshes the comments list
  • ["prestart", orgId, projectId] — refreshes the prestart detail (comment count in tab)

Diary and issue comments additionally route to the single record they belong to, using entity_type and entity_id. A diary comment refreshes that diary’s comment list and its detail; an issue comment refreshes that issue’s comments. An unrecognised entity_type adds no extra invalidation and never fails — the prestart keys above still fire.

Security

  • Add comment: Any project member
  • Edit comment: Author only (not yet implemented in UI)
  • Delete comment: Author OR admin (master_admin, organisational_manager)
  • All queries include tenant isolation

Key Files

FilePurpose
backend/db/queries/comments.sql6 comment queries
backend/api/internal/prestart/service.goComment business logic
apps/web/src/actions/prestarts.tslistComments, createComment, updateComment, deleteComment
apps/web/src/app/_components/prestart-comments.tsxComments UI component