Skip to content

feat(events): registration gating + fullness for atlas redesign - #601

Merged
Ardnived merged 14 commits into
mainfrom
feat/event-registration-gating
Aug 4, 2026
Merged

Ardnived merged 14 commits into
mainfrom
feat/event-registration-gating

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

Carries forward the three unbuilt items from #577 for the Atlas Event Display & Registration Surfaces Redesign (the CMS companion — email items already shipped via #582/#588/#589).

  • Server-side registration gating — POST /api/events/:id/register now refuses an event the client can read but that is closed to registration (external mode / ended / a started limited-run course / full) with a 409 and a stable machine-readable code the widget maps to its registration-state UI.
  • Fullness signal — a denormalized registrationsFull boolean on Events, readable by sahaj-atlas-client on by-id/list reads and the geojson feed at O(1) (no per-event COUNT), exposing capacity without raw counts.
  • Finished-event read contract — pinned + documented: a schedule-elapsed event is finished + _status: 'draft', so it 404s for clients; the pre-job window stays readable and the gate closes the registration hole there.

Changes

  • src/lib/registrations/gating.ts — evaluateRegistrationGate (pure): external → ended (shouldFinish) → started-course → full, each a 409 + code.
  • src/lib/registrations/fullness.ts — isEventFull (the single "full" predicate, shared by the gate and the signal) + syncEventRegistrationsFull (recompute-on-flip, asTrustedReq-elevated write).
  • src/collections/{Registrations,Events}/hooks/syncFullness.ts — maintain the flag on registration create/delete and on capacity edits.
  • src/lib/schedule/scheduleStatus.ts — shouldFinish extracted from ExpireEvents so the job + the gate share one definition.
  • src/collections/Events/endpoints/responseTypes.ts — EventRegistrationErrorCode union (cross-repo contract); customEndpoints.ts documents the 409.

Migration

  • New migration: src/migrations/20260722_190710_registrations_full_flag.ts
  • Impact: adds registrations_full boolean to events (+ _events_v version companion), nullable with DEFAULT false. Existing rows read false until a registration change or capacity edit recomputes them — degrades gracefully (absent/false = never full).
  • Reversible: yes — down drops both columns.

Test Results

  • Unit: 845 passed (adds gating, isEventFull, and shouldFinish specs).
  • Integration: event-registration (37) + registrations-fullness (7) passed — each rejection + the boundary (an open-ended recurring class never closes), the preserved 404, the flag flip/free, blank/external never-full, capacity-edit recompute, and client by-id + geojson selectability.
  • Lint + typecheck: ✓
  • Build: runs on the Railway preview deploy.

Notes for reviewer

  • Soft capacity cap (by design): the count → create window isn't transactional, so a burst of concurrent registrations can overshoot registrationLimit by a few — acceptable for a meditation class (not ticketed inventory); a hard cap would need a row lock / DB constraint. Flagged in code review and documented in the endpoint.
  • gating.ts imports the error-code union from the deliberately self-contained responseTypes.ts (the cross-repo contract file, no @/ imports) — kept that direction so the contract stays the single source of truth; inverting it would break that file's self-containment.
  • Security review: clean (no findings).

Closes #599

🤖 Generated with Claude Code

Ardnived and others added 9 commits July 22, 2026 12:02
Move `shouldFinish` + `FinishCheckInput` out of the ExpireEvents job into
`src/lib/schedule/scheduleStatus.ts` so the registration endpoint can reuse
the same "schedule has run out" check without cross-importing a job's
internals. Behaviour is unchanged; the unit cases move alongside it.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a stored `registrationsFull` boolean on Events so `sahaj-atlas-client`
can read an event's "Full" state on by-id/list reads and the geojson feed
without a per-event COUNT (feed stays O(1)) and without exposing raw
registration numbers. True only for `sahaj-atlas` mode with a set limit the
count has reached; false for external mode or a blank (unlimited) limit.

Maintained by the Registrations create/delete hooks (recompute + write only
on a real flip, so version churn stays negligible) and recomputed on an
Events save when registrationMode / registrationLimit changes. `isEventFull`
is the single shared definition of "full", reused by the registration gate.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Adds the denormalized `registrations_full` boolean (and its `_events_v`
version companion), nullable with default false — existing rows read false
until a registration change or capacity edit recomputes them.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
POST /api/events/:id/register now refuses a registration the event's state
won't accept — external mode, an ended schedule (reuses shouldFinish), a
started limited-run course, or a full event — with a stable machine-readable
`code` (external_registration / event_ended / registration_closed /
event_full, all 409) the Atlas widget maps to its registration-state UI.

The capacity check is enforced against a live count (authoritative); the
published/visible 404 and the open-event 201 path are unchanged. The gate is
a pure, unit-tested helper; the error-code union is typed in the cross-repo
responseTypes contract.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add the `409` response and its four machine-readable `errors[0].code`
values to the hand-authored register-endpoint shim, and guard them in the
custom-endpoints spec so the Atlas contract stays in lockstep.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Document the contract the Atlas widget relies on: a schedule-elapsed event is
marked finished + `_status: 'draft'` by ExpireEvents, so `sahaj-atlas-client`
reads a 404 (finished ⇒ 404, not an readable "Ended" doc). The pre-job window
— past but still published — stays readable so the widget derives "Ended"
client-side, and the register gate closes the matching registration hole.

Stated in the Events collection JSDoc + finishEvent, with an Atlas
read/registration summary in the architecture doc.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Cover each registration rejection (external / ended / started course / full)
plus the boundary (an open-ended recurring class never closes) and the
preserved 404, and the fullness signal (flip at the limit, free on delete,
never-full for blank/external, capacity-edit recompute, client by-id + geojson
selectability with no raw count).

Elevate the fullness recompute's event write with asTrustedReq so the nested
region filterOptions validation isn't rejected by the client query gate.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Parallelize the independent event read + registration count in
  syncEventRegistrationsFull (write-path latency).
- Drop redundant .getTime() in the started-course instant comparison.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Per code review: the count→create window isn't transactional, so concurrent
registrations can overshoot registrationLimit by a few. Acceptable for a
meditation class (not ticketed inventory); documented rather than adding a
row lock / DB constraint. Behaviour unchanged.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-601 July 22, 2026 19:46 Destroyed
@railway-app

railway-app Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-601 environment in sahajcloud

Service Status Web Updated (UTC)
SahajCloud ✅ Success (View Logs) Web Aug 4, 2026 at 12:40 am

@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-601 August 3, 2026 21:51 Destroyed
Reconciles #599 (registration gating + fullness) with main's #603/#604
finished-event overhaul, which landed the same shared surface differently:

- shouldFinish: took main's lastDate-based implementation
  (src/lib/schedule/scheduleStatus.ts) over my upcomingDates-based one; the
  gate's event_ended check + gating.ts now use it (typed via EventScheduleInput),
  and pass `now` through so the gate is evaluated at a single instant.
- Finished-event contract: main keeps finished events *published* (off the
  feeds via excludeFinishedEvents / notFinishedWhere), the opposite of my
  original "finished ⇒ draft ⇒ 404" note. Flipped the Item-3 docs (Events.ts
  JSDoc, architecture.md) to match, and removed main's minimal stopgap
  ended-check in registerForEvent — my full gate (with a machine-readable
  code) supersedes it, as main's own comment anticipated.
- Events hooks: combined main's excludeFinishedEvents (beforeOperation) with
  my syncEventFullness (beforeChange).
- OpenAPI + tests: kept my 4-code register 409 doc/test and main's geojson
  finished-exclusion doc/test; refreshed the gating unit fixtures for the
  lastDate model.
- Migration: dropped my 0722 registrations_full migration and regenerated it
  on top of main's schedule_last_date (0730) so the snapshot chain stays
  cumulative → 20260803_221051_registrations_full_flag.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-601 August 3, 2026 22:37 Destroyed
The origin/main merge regenerated the registrations_full migration as
20260803 (replacing the pre-merge 20260722, so the snapshot chain stays
cumulative on top of schedule_last_date). The PR-601 Railway preview DB
persists across deploys and had already applied the old 20260722 migration,
so a plain `ADD COLUMN` re-add threw "column already exists" and aborted the
in-process boot migration → deploy 502 → all smoke specs down.

Guard the DDL with IF NOT EXISTS / IF EXISTS: a no-op where the column is
already present (identical boolean DEFAULT false), a clean add on a fresh
prod DB. The out-of-order snapshot trap in .claude/rules/migrations.md (#566).

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-601 August 4, 2026 00:13 Destroyed
Ardnived and others added 2 commits August 3, 2026 17:30
origin/main #613 (#606 Phase 2) widened tsconfig.test.json to tests/int/**,
and CI type-checks this PR merged with latest main — surfacing two dormant
errors in my additions:

- createGatingEvent omitted the required `schedule`, so the create fell to the
  draft overload. Wrap it in main's `createData<'events'>` helper and give it a
  default `schedule` (every gating case overrides it).
- registrations-fullness FUTURE_ONE_OFF had `firstDate_tz: string`; make it a
  `SupportedTimezones` literal (`as const`) and wrap the create in `createData`.

Refs #599

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-601 August 4, 2026 00:38 Destroyed
@Ardnived
Ardnived merged commit f6467a7 into main Aug 4, 2026
2 checks passed
@Ardnived
Ardnived deleted the feat/event-registration-gating branch August 4, 2026 00:46
Ardnived added a commit that referenced this pull request Aug 4, 2026
The highest-timestamp snapshot on main
(20260803_221051_registrations_full_flag.json) was stale: it merged in via
PR #601, whose registrations_full migration was generated before #605/#608's
schema landed (region level `venue`, events contact_email / address_venue_name,
translations event_title). Those migrations are timestamped earlier than 0803
but merged later — the out-of-order snapshot trap in .claude/rules/migrations.md.

The next migrate:create would have diffed against that stale snapshot and
re-emitted the already-applied DDL. This lands a no-op migration whose
regenerated .json reflects the full current schema, so the chain is healed:
migrate:create now detects no changes (verified). The .ts does nothing — every
column already ships in an earlier migration.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-601 — 1ec12cef Deployed Aug 4, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(events): registration gating + fullness for atlas redesign

1 participant