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
- On the Activities tab, user clicks “Add Activity”
- An inline card appears with a textarea for the description
- On submit, calls
createActivity(orgId, projectId, prestartId, { description }) - Go handler inserts into
activitieswithprestart_id,project_id,org_id - TanStack Query invalidation refreshes the prestart detail
Edit Activity
- User clicks “Edit” on an activity card
- Description switches to an editable textarea
- On “Save”, calls
updateActivitywith the new description - Go handler uses
COALESCEpattern for partial updates
Delete Activity
- User clicks “Delete” on an activity card
- Confirmation dialog
- Go handler sets
deleted_at = NOW()(soft delete) - 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
- User clicks “Add Resource” on an activity card
- Dialog opens showing project members not already assigned to this activity
- User clicks “Add” next to a member
- Calls
addActivityResource(orgId, projectId, prestartId, activityId, userId) - Go handler inserts into
activity_resources(unique constraint prevents duplicates) - Resource appears as a chip on the activity card
Remove Resource
- User clicks the “x” on a resource chip
- Calls
removeActivityResource(orgId, projectId, prestartId, activityId, userId) - Go handler deletes the
activity_resourcesrow
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.nameThe 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
| File | Purpose |
|---|---|
backend/db/queries/activities.sql | 8 activity + resource queries |
backend/api/internal/prestart/service.go | Activity/resource business logic |
apps/web/src/actions/prestarts.ts | createActivity, updateActivity, deleteActivity, addActivityResource, removeActivityResource |
apps/web/src/app/_components/prestart-detail.tsx | Activities tab UI with resource dialogs |