activity-sport-type: schema, contract, write/read paths, federation

Implements the activity-sport-type change (specs/activity-sport-type):

- db: nullable `sport_type` column on journal.activities + SportType /
  SPORT_TYPES (text().$type<> convention).
- api: optional sportType on the activity read + create schemas (mirrored
  SPORT_TYPES; @trails-cool/api stays zod-only).
- write: ActivityInput + createActivity persist it; mapSportType() normalizes
  provider strings (Komoot bulk import passes tour.sport; Garmin unset);
  threaded through the unified importActivity.
- read/display: sportType added to the detail/feed/profile loaders and the v1
  REST endpoints; shared SportBadge (glyph + i18n label) on detail, feed, and
  profile; sport-aware feed verb; create-form <select>.
- i18n: journal.activities.sport.* (labels + verbs) in en + de.
- federation: `sport` PropertyValue on the Note when set.

Tests: mapSportType unit table; federation asserts the sport attachment is
present when set and omitted when unset. typecheck + lint + unit all green.
E2E (create→badge) still to add.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-06-12 14:11:41 +02:00
parent ee76945f20
commit 2cb32cd2d3
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9
25 changed files with 328 additions and 18 deletions

View file

@ -1,10 +1,29 @@
import { z } from "zod";
/**
* Sport / activity type. Must stay in sync with `SPORT_TYPES` in
* `@trails-cool/db` (schema/journal.ts) this package is intentionally
* standalone (zod only), so the wire enum is mirrored here.
*/
export const SPORT_TYPES = [
"hike",
"walk",
"run",
"ride",
"gravel",
"mtb",
"ski",
"other",
] as const;
export const SportTypeSchema = z.enum(SPORT_TYPES);
export type SportType = z.infer<typeof SportTypeSchema>;
/** Activity summary for list views */
export const ActivitySummarySchema = z.object({
id: z.uuid(),
name: z.string(),
description: z.string(),
sportType: SportTypeSchema.nullable(),
routeId: z.uuid().nullable(),
routeName: z.string().nullable(),
distance: z.number().nullable(),
@ -32,6 +51,7 @@ export const ActivityListResponseSchema = z.object({
export const CreateActivityRequestSchema = z.object({
name: z.string().min(1).max(200),
description: z.string().max(5000).default(""),
sportType: SportTypeSchema.optional(),
gpx: z.string().optional(),
routeId: z.uuid().optional(),
startedAt: z.iso.datetime().optional(),

View file

@ -47,9 +47,11 @@ export {
ActivitySummarySchema, ActivityDetailSchema,
ActivityListResponseSchema,
CreateActivityRequestSchema, CreateActivityResponseSchema,
SPORT_TYPES, SportTypeSchema,
type ActivitySummary, type ActivityDetail,
type ActivityListResponse,
type CreateActivityRequest, type CreateActivityResponse,
type SportType,
} from "./activities.ts";
// Uploads

View file

@ -142,6 +142,24 @@ export const routeVersions = journalSchema.table("route_versions", {
*/
export type Audience = "public" | "followers-only";
/**
* Sport / activity type. Nullable on activities (NULL = unspecified, which
* is always valid). Stored as a plain text() column with a `.$type<>` guard,
* matching the visibility/audience convention (no pgEnum). `SPORT_TYPES` is
* the runtime source of truth for validation and iteration.
*/
export const SPORT_TYPES = [
"hike",
"walk",
"run",
"ride",
"gravel",
"mtb",
"ski",
"other",
] as const;
export type SportType = (typeof SPORT_TYPES)[number];
export const activities = journalSchema.table("activities", {
id: text("id").primaryKey(),
// Local author. NULL for activities ingested from a remote trails
@ -153,6 +171,8 @@ export const activities = journalSchema.table("activities", {
routeId: text("route_id").references(() => routes.id),
name: text("name").notNull(),
description: text("description").default(""),
// Sport / activity type (NULL = unspecified). See SPORT_TYPES above.
sportType: text("sport_type").$type<SportType>(),
gpx: text("gpx"),
geom: lineString("geom"),
startedAt: timestamp("started_at", { withTimezone: true }),

View file

@ -365,6 +365,28 @@ export default {
delete: "Aktivität löschen",
deleteConfirm: "Möchtest du diese Aktivität wirklich löschen?",
importedFrom: "Importiert von {{provider}}",
sport: {
label: "Sportart",
unspecified: "Nicht angegeben",
hike: "Wandern",
walk: "Gehen",
run: "Laufen",
ride: "Radfahren",
gravel: "Gravel",
mtb: "Mountainbike",
ski: "Ski",
other: "Sonstiges",
verb: {
hike: "war wandern",
walk: "war spazieren",
run: "war laufen",
ride: "war Rad fahren",
gravel: "war Gravel fahren",
mtb: "war Mountainbiken",
ski: "war Ski fahren",
other: "hat eine Aktivität erfasst",
},
},
sortByDate: "Aktivitätsdatum",
sortByAdded: "Hinzugefügt am",
visibility: {

View file

@ -365,6 +365,28 @@ export default {
delete: "Delete Activity",
deleteConfirm: "Are you sure you want to delete this activity?",
importedFrom: "Imported from {{provider}}",
sport: {
label: "Sport",
unspecified: "Unspecified",
hike: "Hike",
walk: "Walk",
run: "Run",
ride: "Ride",
gravel: "Gravel",
mtb: "Mountain bike",
ski: "Ski",
other: "Other",
verb: {
hike: "went hiking",
walk: "went for a walk",
run: "went for a run",
ride: "went for a ride",
gravel: "went gravel riding",
mtb: "went mountain biking",
ski: "went skiing",
other: "logged an activity",
},
},
sortByDate: "Activity date",
sortByAdded: "Date added",
visibility: {