User activity favorite
Purpose
TBD by human
Identity & key fields
- Primary key:
id(uuid, defaultgen_random_uuid()). userId(uuid, FK →users.users.id, on-delete cascade).activityId(uuid, FK →activities.activities.id, on-delete cascade).createdAt(timestamptz, defaultnow()).
business meaning: TBD by human
Invariants
- UNIQUE on
(userId, activityId)viauser_activity_favorites_user_activity_unique— a user cannot favorite the same activity twice (enforced in tktspace-backend/libs/shared/data-access-db/src/lib/schema/activities.schema.ts). - Both FKs ON DELETE CASCADE (enforced in tktspace-backend/libs/shared/data-access-db/src/lib/schema/activities.schema.ts).
- Indexes:
user_activity_favorites_user_id_created_at_idxon(userId, createdAt DESC);user_activity_favorites_activity_id_idxon(activityId)(enforced in tktspace-backend/libs/shared/data-access-db/src/lib/schema/activities.schema.ts).
business invariants: TBD by human
Lifecycle
No explicit lifecycle — added or removed.
Relationships
- User (ENT-021) —
userId→users.users.id, on-delete cascade. N:1. - Activity (ENT-005) —
activityId→activities.activities.id, on-delete cascade. N:1.
API surfaces
| Surface | Exposed | Notes |
|---|---|---|
| client | yes — /favorites, /favorites/{activityId} (FavoriteListResponseDto, FavoriteRecordDto, FavoriteActivityDto, CreateFavoriteDto). Phase C (869dpxbj6): FavoriteActivityDto.type promoted from bare-string to a named ActivityType enum $ref (@ApiProperty({ enum: ActivityType, enumName: 'ActivityType' })). Enum domain narrows to [SLOT_BASED, SERVICE]. Generated mobile client now emits the named enum. See ADR activity-model-simplification §D5. | Swagger UI |
| business | yes — /analytics/favorites (FavoriteActivityAnalyticsItemDto) — aggregated counts, not per-user rows | Swagger UI |
| super-admin | no | — |
The business surface exposes aggregated analytics only; per-user rows are not visible to the company.
Known gotchas / open questions
userIdreferences the platform-wideusers.users.id, not the per-companycompany_customer.id. Favourites are user-level, not per-company.