ModulesPrestartsFeaturesActivities & Resources

Activities & Resources

Activities describe specific work items within a prestart. Each activity can have multiple resources (workers) assigned to it.

Activity Model

Activities are designed as a shared entity — they link to prestart_id now and will also link to diary_id in the future. This allows the same activity structure to be reused across both modules without duplication.

Create Activity

  1. On the Activities tab, user clicks “Add Activity”
  2. An inline card appears with a textarea for the description
  3. On submit, calls createActivity(orgId, projectId, prestartId, { description })
  4. Go handler inserts into activities with prestart_id, project_id, org_id
  5. TanStack Query invalidation refreshes the prestart detail

Edit Activity

  1. User clicks “Edit” on an activity card
  2. Description switches to an editable textarea
  3. On “Save”, calls updateActivity with the new description
  4. Go handler uses COALESCE pattern for partial updates

Delete Activity

  1. User clicks “Delete” on an activity card
  2. Confirmation dialog
  3. Go handler sets deleted_at = NOW() (soft delete)
  4. Cascades: activity resources and files are still preserved in DB but won’t appear in queries (filtered by deleted_at IS NULL)

Resource Assignment

Resources are project members assigned to work on an activity. Managed via a picker dialog.

Add Resource

  1. User clicks “Add Resource” on an activity card
  2. Dialog opens showing project members not already assigned to this activity
  3. User clicks “Add” next to a member
  4. Calls addActivityResource(orgId, projectId, prestartId, activityId, userId)
  5. Go handler inserts into activity_resources (unique constraint prevents duplicates)
  6. Resource appears as a chip on the activity card

Remove Resource

  1. User clicks the “x” on a resource chip
  2. Calls removeActivityResource(orgId, projectId, prestartId, activityId, userId)
  3. Go handler deletes the activity_resources row

Resource Query

All resources for a prestart are fetched in a single query for efficiency:

SELECT ar.id, ar.activity_id, ar.user_id, u.name, u.email, u.role, ar.created_at
FROM activity_resources ar
JOIN users u ON u.id = ar.user_id
JOIN activities a ON a.id = ar.activity_id
WHERE a.prestart_id = $1 AND a.deleted_at IS NULL
ORDER BY ar.activity_id, u.name

The Go service groups these by activity_id and attaches them to the correct activity in the response.

Security

  • Only the prestart creator or an admin can manage activities and resources
  • All queries include tenant isolation (AND org_id = $org_id)
  • Activity operations verify the activity belongs to the specified prestart

Key Files

FilePurpose
backend/db/queries/activities.sql8 activity + resource queries
backend/api/internal/prestart/service.goActivity/resource business logic
apps/web/src/actions/prestarts.tscreateActivity, updateActivity, deleteActivity, addActivityResource, removeActivityResource
apps/web/src/app/_components/prestart-detail.tsxActivities tab UI with resource dialogs