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
- User types in the comment input at the bottom of the Comments tab
- Clicks “Post” (disabled when empty or while submitting)
- Calls
createComment(orgId, projectId, prestartId, content) - Go handler inserts into
commentswithuser_idfrom session - TanStack Query invalidation refreshes the comment list
Delete Comment
- User clicks “Delete” on their own comment (or any comment if admin)
- Confirmation dialog
- Calls
deleteComment(orgId, projectId, prestartId, commentId) - Go handler sets
deleted_at = NOW()(soft delete) - 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
| File | Purpose |
|---|---|
backend/db/queries/comments.sql | 6 comment queries |
backend/api/internal/prestart/service.go | Comment business logic |
apps/web/src/actions/prestarts.ts | listComments, createComment, updateComment, deleteComment |
apps/web/src/app/_components/prestart-comments.tsx | Comments UI component |