@kelpie/server 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +13 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +8 -1
- package/dist/app.js.map +1 -1
- package/dist/boot.d.ts.map +1 -1
- package/dist/boot.js +1 -0
- package/dist/boot.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/apiKeyScopes.d.ts.map +1 -1
- package/dist/lib/apiKeyScopes.js +6 -0
- package/dist/lib/apiKeyScopes.js.map +1 -1
- package/dist/lib/columns.d.ts +6 -0
- package/dist/lib/columns.d.ts.map +1 -1
- package/dist/lib/columns.js +5 -3
- package/dist/lib/columns.js.map +1 -1
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +3 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/egress.d.ts.map +1 -1
- package/dist/lib/egress.js +8 -4
- package/dist/lib/egress.js.map +1 -1
- package/dist/lib/errors.d.ts +18 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +25 -0
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/ids.d.ts +11 -0
- package/dist/lib/ids.d.ts.map +1 -1
- package/dist/lib/ids.js +11 -0
- package/dist/lib/ids.js.map +1 -1
- package/dist/lib/kelpieConfigFile.d.ts +15 -1
- package/dist/lib/kelpieConfigFile.d.ts.map +1 -1
- package/dist/lib/kelpieConfigFile.js +33 -1
- package/dist/lib/kelpieConfigFile.js.map +1 -1
- package/dist/modules/agent-tasks/catalog.d.ts.map +1 -1
- package/dist/modules/agent-tasks/catalog.js +32 -1
- package/dist/modules/agent-tasks/catalog.js.map +1 -1
- package/dist/modules/agent-tasks/index.d.ts.map +1 -1
- package/dist/modules/agent-tasks/index.js +1 -0
- package/dist/modules/agent-tasks/index.js.map +1 -1
- package/dist/modules/agent-tasks/resolve.d.ts.map +1 -1
- package/dist/modules/agent-tasks/resolve.js +5 -0
- package/dist/modules/agent-tasks/resolve.js.map +1 -1
- package/dist/modules/agent-tasks/routes.d.ts +2 -0
- package/dist/modules/agent-tasks/routes.d.ts.map +1 -1
- package/dist/modules/attachedRecords.d.ts +22 -8
- package/dist/modules/attachedRecords.d.ts.map +1 -1
- package/dist/modules/attachedRecords.js +42 -5
- package/dist/modules/attachedRecords.js.map +1 -1
- package/dist/modules/auth/index.d.ts.map +1 -1
- package/dist/modules/auth/index.js +22 -4
- package/dist/modules/auth/index.js.map +1 -1
- package/dist/modules/auth/repository.d.ts +16 -1
- package/dist/modules/auth/repository.d.ts.map +1 -1
- package/dist/modules/auth/repository.js +21 -2
- package/dist/modules/auth/repository.js.map +1 -1
- package/dist/modules/auth/routes.d.ts.map +1 -1
- package/dist/modules/auth/routes.js +32 -6
- package/dist/modules/auth/routes.js.map +1 -1
- package/dist/modules/auth/schema.d.ts +18 -1
- package/dist/modules/auth/schema.d.ts.map +1 -1
- package/dist/modules/auth/schema.js +12 -1
- package/dist/modules/auth/schema.js.map +1 -1
- package/dist/modules/auth/service.d.ts +46 -0
- package/dist/modules/auth/service.d.ts.map +1 -1
- package/dist/modules/auth/service.js +167 -10
- package/dist/modules/auth/service.js.map +1 -1
- package/dist/modules/auth/session.d.ts +12 -0
- package/dist/modules/auth/session.d.ts.map +1 -1
- package/dist/modules/auth/session.js +12 -0
- package/dist/modules/auth/session.js.map +1 -1
- package/dist/modules/companies/repository.d.ts.map +1 -1
- package/dist/modules/companies/repository.js +1 -1
- package/dist/modules/companies/repository.js.map +1 -1
- package/dist/modules/companies/routes.d.ts +2 -4
- package/dist/modules/companies/routes.d.ts.map +1 -1
- package/dist/modules/companies/routes.js +6 -11
- package/dist/modules/companies/routes.js.map +1 -1
- package/dist/modules/companies/schema.d.ts +13 -28
- package/dist/modules/companies/schema.d.ts.map +1 -1
- package/dist/modules/companies/schema.js +2 -2
- package/dist/modules/companies/schema.js.map +1 -1
- package/dist/modules/companies/service.d.ts +2 -3
- package/dist/modules/companies/service.d.ts.map +1 -1
- package/dist/modules/companies/service.js +4 -7
- package/dist/modules/companies/service.js.map +1 -1
- package/dist/modules/core.d.ts.map +1 -1
- package/dist/modules/core.js +2 -0
- package/dist/modules/core.js.map +1 -1
- package/dist/modules/custom-fields/repository.d.ts.map +1 -1
- package/dist/modules/custom-fields/repository.js +2 -0
- package/dist/modules/custom-fields/repository.js.map +1 -1
- package/dist/modules/custom-fields/routes.d.ts +1 -0
- package/dist/modules/custom-fields/routes.d.ts.map +1 -1
- package/dist/modules/dashboard/index.d.ts.map +1 -1
- package/dist/modules/dashboard/index.js +1 -0
- package/dist/modules/dashboard/index.js.map +1 -1
- package/dist/modules/dashboard/repository.d.ts +13 -0
- package/dist/modules/dashboard/repository.d.ts.map +1 -1
- package/dist/modules/dashboard/repository.js +36 -0
- package/dist/modules/dashboard/repository.js.map +1 -1
- package/dist/modules/dashboard/routes.d.ts.map +1 -1
- package/dist/modules/dashboard/routes.js +13 -0
- package/dist/modules/dashboard/routes.js.map +1 -1
- package/dist/modules/dashboard/service.d.ts +11 -0
- package/dist/modules/dashboard/service.d.ts.map +1 -1
- package/dist/modules/dashboard/service.js +24 -1
- package/dist/modules/dashboard/service.js.map +1 -1
- package/dist/modules/decisions/repository.d.ts.map +1 -1
- package/dist/modules/decisions/repository.js +2 -0
- package/dist/modules/decisions/repository.js.map +1 -1
- package/dist/modules/decisions/routes.d.ts +2 -0
- package/dist/modules/decisions/routes.d.ts.map +1 -1
- package/dist/modules/events/attendances.d.ts +35 -0
- package/dist/modules/events/attendances.d.ts.map +1 -0
- package/dist/modules/events/attendances.js +157 -0
- package/dist/modules/events/attendances.js.map +1 -0
- package/dist/modules/events/catalog.d.ts +35 -0
- package/dist/modules/events/catalog.d.ts.map +1 -0
- package/dist/modules/events/catalog.js +11 -0
- package/dist/modules/events/catalog.js.map +1 -0
- package/dist/modules/events/index.d.ts +10 -0
- package/dist/modules/events/index.d.ts.map +1 -0
- package/dist/modules/events/index.js +47 -0
- package/dist/modules/events/index.js.map +1 -0
- package/dist/modules/events/repository.d.ts +67 -0
- package/dist/modules/events/repository.d.ts.map +1 -0
- package/dist/modules/events/repository.js +212 -0
- package/dist/modules/events/repository.js.map +1 -0
- package/dist/modules/events/routes.d.ts +136 -0
- package/dist/modules/events/routes.d.ts.map +1 -0
- package/dist/modules/events/routes.js +280 -0
- package/dist/modules/events/routes.js.map +1 -0
- package/dist/modules/events/schema.d.ts +626 -0
- package/dist/modules/events/schema.d.ts.map +1 -0
- package/dist/modules/events/schema.js +93 -0
- package/dist/modules/events/schema.js.map +1 -0
- package/dist/modules/events/service.d.ts +68 -0
- package/dist/modules/events/service.d.ts.map +1 -0
- package/dist/modules/events/service.js +262 -0
- package/dist/modules/events/service.js.map +1 -0
- package/dist/modules/events/tools.d.ts +8 -0
- package/dist/modules/events/tools.d.ts.map +1 -0
- package/dist/modules/events/tools.js +80 -0
- package/dist/modules/events/tools.js.map +1 -0
- package/dist/modules/forms/applySubmissionFields.d.ts.map +1 -1
- package/dist/modules/forms/applySubmissionFields.js +7 -5
- package/dist/modules/forms/applySubmissionFields.js.map +1 -1
- package/dist/modules/forms/fillAddresses.d.ts +4 -0
- package/dist/modules/forms/fillAddresses.d.ts.map +1 -0
- package/dist/modules/forms/fillAddresses.js +93 -0
- package/dist/modules/forms/fillAddresses.js.map +1 -0
- package/dist/modules/forms/repository.d.ts +2 -2
- package/dist/modules/forms/repository.d.ts.map +1 -1
- package/dist/modules/forms/repository.js.map +1 -1
- package/dist/modules/forms/routes.d.ts +2 -0
- package/dist/modules/forms/routes.d.ts.map +1 -1
- package/dist/modules/forms/routes.js +2 -2
- package/dist/modules/forms/routes.js.map +1 -1
- package/dist/modules/forms/schema.js +2 -2
- package/dist/modules/forms/schema.js.map +1 -1
- package/dist/modules/forms/service.js +2 -2
- package/dist/modules/forms/service.js.map +1 -1
- package/dist/modules/forms/submission.d.ts +1 -0
- package/dist/modules/forms/submission.d.ts.map +1 -1
- package/dist/modules/forms/submission.js +27 -4
- package/dist/modules/forms/submission.js.map +1 -1
- package/dist/modules/hiring/roles.d.ts.map +1 -1
- package/dist/modules/hiring/roles.js +2 -1
- package/dist/modules/hiring/roles.js.map +1 -1
- package/dist/modules/import-export/addresses.d.ts +22 -0
- package/dist/modules/import-export/addresses.d.ts.map +1 -0
- package/dist/modules/import-export/addresses.js +83 -0
- package/dist/modules/import-export/addresses.js.map +1 -0
- package/dist/modules/import-export/drafts.d.ts +3 -4
- package/dist/modules/import-export/drafts.d.ts.map +1 -1
- package/dist/modules/import-export/drafts.js +4 -5
- package/dist/modules/import-export/drafts.js.map +1 -1
- package/dist/modules/import-export/exportRows.d.ts.map +1 -1
- package/dist/modules/import-export/exportRows.js +3 -3
- package/dist/modules/import-export/exportRows.js.map +1 -1
- package/dist/modules/import-export/plan.d.ts.map +1 -1
- package/dist/modules/import-export/plan.js +17 -2
- package/dist/modules/import-export/plan.js.map +1 -1
- package/dist/modules/import-export/presets.d.ts.map +1 -1
- package/dist/modules/import-export/presets.js +52 -7
- package/dist/modules/import-export/presets.js.map +1 -1
- package/dist/modules/import-export/repository.d.ts +3 -4
- package/dist/modules/import-export/repository.d.ts.map +1 -1
- package/dist/modules/import-export/repository.js +2 -3
- package/dist/modules/import-export/repository.js.map +1 -1
- package/dist/modules/import-export/writes.d.ts.map +1 -1
- package/dist/modules/import-export/writes.js +8 -4
- package/dist/modules/import-export/writes.js.map +1 -1
- package/dist/modules/lists/routes.d.ts +4 -0
- package/dist/modules/lists/routes.d.ts.map +1 -1
- package/dist/modules/notes/routes.d.ts +2 -0
- package/dist/modules/notes/routes.d.ts.map +1 -1
- package/dist/modules/people/repository.d.ts.map +1 -1
- package/dist/modules/people/repository.js +1 -1
- package/dist/modules/people/repository.js.map +1 -1
- package/dist/modules/people/routes.d.ts +2 -2
- package/dist/modules/people/routes.js +6 -6
- package/dist/modules/people/routes.js.map +1 -1
- package/dist/modules/people/schema.d.ts +17 -14
- package/dist/modules/people/schema.d.ts.map +1 -1
- package/dist/modules/people/schema.js +6 -4
- package/dist/modules/people/schema.js.map +1 -1
- package/dist/modules/people/service.d.ts +2 -2
- package/dist/modules/people/service.d.ts.map +1 -1
- package/dist/modules/people/service.js +5 -4
- package/dist/modules/people/service.js.map +1 -1
- package/dist/modules/plans/repository.d.ts +2 -2
- package/dist/modules/plans/repository.d.ts.map +1 -1
- package/dist/modules/plans/routes.d.ts +1 -0
- package/dist/modules/plans/routes.d.ts.map +1 -1
- package/dist/modules/plans/routes.js +4 -4
- package/dist/modules/plans/routes.js.map +1 -1
- package/dist/modules/plans/schema.d.ts +2 -2
- package/dist/modules/plans/schema.d.ts.map +1 -1
- package/dist/modules/plans/schema.js +3 -3
- package/dist/modules/plans/schema.js.map +1 -1
- package/dist/modules/plans/service.d.ts +2 -2
- package/dist/modules/plans/service.d.ts.map +1 -1
- package/dist/modules/plans/service.js.map +1 -1
- package/dist/modules/plans/tools.js +2 -2
- package/dist/modules/plans/tools.js.map +1 -1
- package/dist/modules/recordTargets.d.ts.map +1 -1
- package/dist/modules/recordTargets.js +11 -0
- package/dist/modules/recordTargets.js.map +1 -1
- package/dist/modules/references.d.ts.map +1 -1
- package/dist/modules/references.js +2 -0
- package/dist/modules/references.js.map +1 -1
- package/dist/modules/sample-data/fixture.d.ts +26 -4
- package/dist/modules/sample-data/fixture.d.ts.map +1 -1
- package/dist/modules/sample-data/fixture.js +157 -23
- package/dist/modules/sample-data/fixture.js.map +1 -1
- package/dist/modules/sample-data/index.d.ts +5 -2
- package/dist/modules/sample-data/index.d.ts.map +1 -1
- package/dist/modules/sample-data/index.js +7 -2
- package/dist/modules/sample-data/index.js.map +1 -1
- package/dist/modules/sample-data/routes.d.ts.map +1 -1
- package/dist/modules/sample-data/routes.js +2 -0
- package/dist/modules/sample-data/routes.js.map +1 -1
- package/dist/modules/sample-data/service.d.ts +11 -3
- package/dist/modules/sample-data/service.d.ts.map +1 -1
- package/dist/modules/sample-data/service.js +452 -363
- package/dist/modules/sample-data/service.js.map +1 -1
- package/dist/modules/sample-data/tools.d.ts.map +1 -1
- package/dist/modules/sample-data/tools.js +4 -3
- package/dist/modules/sample-data/tools.js.map +1 -1
- package/dist/modules/search/index.d.ts +1 -1
- package/dist/modules/search/index.d.ts.map +1 -1
- package/dist/modules/search/index.js +2 -1
- package/dist/modules/search/index.js.map +1 -1
- package/dist/modules/search/repository.d.ts +1 -0
- package/dist/modules/search/repository.d.ts.map +1 -1
- package/dist/modules/search/repository.js +22 -0
- package/dist/modules/search/repository.js.map +1 -1
- package/dist/modules/search/service.d.ts +2 -2
- package/dist/modules/search/service.d.ts.map +1 -1
- package/dist/modules/search/service.js +4 -3
- package/dist/modules/search/service.js.map +1 -1
- package/dist/modules/smtp-email/index.d.ts +12 -4
- package/dist/modules/smtp-email/index.d.ts.map +1 -1
- package/dist/modules/smtp-email/index.js +25 -5
- package/dist/modules/smtp-email/index.js.map +1 -1
- package/dist/modules/workspace/repository.d.ts +2 -0
- package/dist/modules/workspace/repository.d.ts.map +1 -1
- package/dist/modules/workspace/repository.js +12 -0
- package/dist/modules/workspace/repository.js.map +1 -1
- package/dist/modules/workspace/routes.d.ts.map +1 -1
- package/dist/modules/workspace/routes.js +13 -0
- package/dist/modules/workspace/routes.js.map +1 -1
- package/dist/modules/workspace/service.d.ts +10 -0
- package/dist/modules/workspace/service.d.ts.map +1 -1
- package/dist/modules/workspace/service.js +34 -10
- package/dist/modules/workspace/service.js.map +1 -1
- package/dist/modules/workspace/starters.d.ts +17 -2
- package/dist/modules/workspace/starters.d.ts.map +1 -1
- package/dist/modules/workspace/starters.js +141 -14
- package/dist/modules/workspace/starters.js.map +1 -1
- package/dist/modules/workspace/workspaceAccessMiddleware.d.ts.map +1 -1
- package/dist/modules/workspace/workspaceAccessMiddleware.js +3 -4
- package/dist/modules/workspace/workspaceAccessMiddleware.js.map +1 -1
- package/dist/runtime/events.d.ts +1 -1
- package/dist/runtime/events.d.ts.map +1 -1
- package/dist/runtime/events.js +2 -0
- package/dist/runtime/events.js.map +1 -1
- package/dist/runtime/module.d.ts +71 -1
- package/dist/runtime/module.d.ts.map +1 -1
- package/dist/runtime/registry.d.ts.map +1 -1
- package/dist/runtime/registry.js +142 -9
- package/dist/runtime/registry.js.map +1 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -0
- package/dist/schema/index.js.map +1 -1
- package/dist/testing/app.d.ts +8 -0
- package/dist/testing/app.d.ts.map +1 -1
- package/dist/testing/app.js +6 -1
- package/dist/testing/app.js.map +1 -1
- package/dist/testing/client.d.ts.map +1 -1
- package/dist/testing/client.js +9 -1
- package/dist/testing/client.js.map +1 -1
- package/migrations/0043_external_sign_in.sql +2 -0
- package/migrations/0044_events.sql +79 -0
- package/migrations/0045_addresses.sql +66 -0
- package/migrations/0046_drop_company_website.sql +66 -0
- package/migrations/meta/_journal.json +28 -0
- package/package.json +3 -3
- package/src/app.ts +25 -1
- package/src/boot.ts +1 -0
- package/src/index.ts +13 -1
- package/src/lib/apiKeyScopes.ts +6 -0
- package/src/lib/columns.ts +12 -3
- package/src/lib/config.ts +21 -0
- package/src/lib/egress.ts +8 -4
- package/src/lib/errors.ts +37 -0
- package/src/lib/ids.ts +11 -0
- package/src/lib/kelpieConfigFile.ts +69 -1
- package/src/modules/agent-tasks/catalog.ts +33 -1
- package/src/modules/agent-tasks/index.ts +1 -0
- package/src/modules/agent-tasks/resolve.ts +11 -0
- package/src/modules/attachedRecords.ts +85 -13
- package/src/modules/auth/index.ts +26 -4
- package/src/modules/auth/repository.ts +36 -4
- package/src/modules/auth/routes.ts +46 -9
- package/src/modules/auth/schema.ts +12 -1
- package/src/modules/auth/service.ts +261 -10
- package/src/modules/auth/session.ts +14 -0
- package/src/modules/companies/repository.ts +1 -0
- package/src/modules/companies/routes.ts +6 -11
- package/src/modules/companies/schema.ts +3 -3
- package/src/modules/companies/service.ts +6 -10
- package/src/modules/core.ts +2 -0
- package/src/modules/custom-fields/repository.ts +2 -0
- package/src/modules/dashboard/index.ts +1 -0
- package/src/modules/dashboard/repository.ts +64 -0
- package/src/modules/dashboard/routes.ts +15 -0
- package/src/modules/dashboard/service.ts +48 -0
- package/src/modules/decisions/repository.ts +2 -0
- package/src/modules/events/attendances.ts +245 -0
- package/src/modules/events/catalog.ts +36 -0
- package/src/modules/events/index.ts +54 -0
- package/src/modules/events/repository.ts +396 -0
- package/src/modules/events/routes.ts +405 -0
- package/src/modules/events/schema.ts +148 -0
- package/src/modules/events/service.ts +443 -0
- package/src/modules/events/tools.ts +118 -0
- package/src/modules/forms/applySubmissionFields.ts +7 -5
- package/src/modules/forms/fillAddresses.ts +185 -0
- package/src/modules/forms/repository.ts +3 -3
- package/src/modules/forms/routes.ts +2 -2
- package/src/modules/forms/schema.ts +2 -2
- package/src/modules/forms/service.ts +2 -2
- package/src/modules/forms/submission.ts +34 -4
- package/src/modules/hiring/roles.ts +2 -1
- package/src/modules/import-export/addresses.ts +150 -0
- package/src/modules/import-export/drafts.ts +7 -9
- package/src/modules/import-export/exportRows.ts +3 -3
- package/src/modules/import-export/plan.ts +30 -2
- package/src/modules/import-export/presets.ts +55 -7
- package/src/modules/import-export/repository.ts +5 -7
- package/src/modules/import-export/writes.ts +8 -4
- package/src/modules/people/repository.ts +1 -0
- package/src/modules/people/routes.ts +6 -6
- package/src/modules/people/schema.ts +7 -5
- package/src/modules/people/service.ts +7 -5
- package/src/modules/plans/repository.ts +2 -2
- package/src/modules/plans/routes.ts +6 -6
- package/src/modules/plans/schema.ts +4 -4
- package/src/modules/plans/service.ts +3 -3
- package/src/modules/plans/tools.ts +2 -2
- package/src/modules/recordTargets.ts +14 -0
- package/src/modules/references.ts +2 -0
- package/src/modules/sample-data/fixture.ts +208 -27
- package/src/modules/sample-data/index.ts +7 -2
- package/src/modules/sample-data/routes.ts +2 -0
- package/src/modules/sample-data/service.ts +166 -49
- package/src/modules/sample-data/tools.ts +4 -3
- package/src/modules/search/index.ts +2 -1
- package/src/modules/search/repository.ts +32 -1
- package/src/modules/search/service.ts +6 -4
- package/src/modules/smtp-email/index.ts +32 -10
- package/src/modules/workspace/repository.ts +18 -0
- package/src/modules/workspace/routes.ts +16 -0
- package/src/modules/workspace/service.ts +59 -14
- package/src/modules/workspace/starters.ts +275 -14
- package/src/modules/workspace/workspaceAccessMiddleware.ts +3 -4
- package/src/runtime/events.ts +2 -0
- package/src/runtime/module.ts +78 -1
- package/src/runtime/registry.ts +176 -8
- package/src/schema/index.ts +1 -0
- package/src/testing/app.ts +14 -1
- package/src/testing/client.ts +11 -1
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ATTENDANCE_SOURCES,
|
|
3
|
+
ATTENDANCE_STATUSES,
|
|
4
|
+
EVENT_ASSOCIATION_TARGET_TYPES,
|
|
5
|
+
EVENT_FORMATS,
|
|
6
|
+
EVENT_STATUSES,
|
|
7
|
+
customFieldsPatchShape,
|
|
8
|
+
} from '@kelpie/schemas'
|
|
9
|
+
import type { EventAssociationTargetType } from '@kelpie/schemas'
|
|
10
|
+
import type { Context, Hono } from 'hono'
|
|
11
|
+
import { z } from 'zod'
|
|
12
|
+
|
|
13
|
+
import { AppError } from '../../lib/errors.ts'
|
|
14
|
+
import { pageBody, readIdFilter, readJsonBody, readListParameters } from '../../lib/http.ts'
|
|
15
|
+
import { renderCustomFieldsForWire } from '../custom-fields/wire.ts'
|
|
16
|
+
import type { Actor } from '../auth/actor.ts'
|
|
17
|
+
import { resolveActorFrom } from '../auth/credentials.ts'
|
|
18
|
+
import type { CredentialDependencies } from '../auth/credentials.ts'
|
|
19
|
+
import type {
|
|
20
|
+
AttendanceView,
|
|
21
|
+
AttendancesService,
|
|
22
|
+
CreateAttendanceInput,
|
|
23
|
+
UpdateAttendanceInput,
|
|
24
|
+
} from './attendances.ts'
|
|
25
|
+
import type { CreateEventInput, EventView, EventsService, UpdateEventInput } from './service.ts'
|
|
26
|
+
import type { AssociationRef } from './repository.ts'
|
|
27
|
+
|
|
28
|
+
const isoTimestamp = z.iso.datetime()
|
|
29
|
+
|
|
30
|
+
const associationBody = z.strictObject({
|
|
31
|
+
target_type: z.enum(EVENT_ASSOCIATION_TARGET_TYPES),
|
|
32
|
+
target_id: z.string().min(1),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const eventShape = {
|
|
36
|
+
name: z.string().min(1),
|
|
37
|
+
kind: z.string(),
|
|
38
|
+
starts_at: isoTimestamp,
|
|
39
|
+
ends_at: isoTimestamp,
|
|
40
|
+
timezone: z.string().min(1),
|
|
41
|
+
location: z.string(),
|
|
42
|
+
meeting_url: z.string().url().nullable(),
|
|
43
|
+
format: z.enum(EVENT_FORMATS),
|
|
44
|
+
details: z.string(),
|
|
45
|
+
status: z.enum(EVENT_STATUSES),
|
|
46
|
+
owner_id: z.string().min(1).nullable(),
|
|
47
|
+
summary: z.string(),
|
|
48
|
+
tags: z.array(z.string().min(1)),
|
|
49
|
+
associations: z.array(associationBody),
|
|
50
|
+
custom_fields: customFieldsPatchShape,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const createEventBody = z.strictObject({
|
|
54
|
+
...eventShape,
|
|
55
|
+
kind: eventShape.kind.default(''),
|
|
56
|
+
timezone: eventShape.timezone.optional(),
|
|
57
|
+
location: eventShape.location.default(''),
|
|
58
|
+
meeting_url: eventShape.meeting_url.default(null),
|
|
59
|
+
details: eventShape.details.default(''),
|
|
60
|
+
status: eventShape.status.default('scheduled'),
|
|
61
|
+
owner_id: eventShape.owner_id.optional(),
|
|
62
|
+
summary: eventShape.summary.default(''),
|
|
63
|
+
tags: eventShape.tags.default([]),
|
|
64
|
+
associations: eventShape.associations.default([]),
|
|
65
|
+
custom_fields: eventShape.custom_fields.default({}),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
export const updateEventBody = z.strictObject(eventShape).partial()
|
|
69
|
+
|
|
70
|
+
const attendanceShape = {
|
|
71
|
+
event_id: z.string().min(1),
|
|
72
|
+
person_id: z.string().min(1),
|
|
73
|
+
status: z.enum(ATTENDANCE_STATUSES),
|
|
74
|
+
source: z.enum(ATTENDANCE_SOURCES),
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const createAttendanceBody = z.strictObject({
|
|
78
|
+
...attendanceShape,
|
|
79
|
+
status: attendanceShape.status.default('registered'),
|
|
80
|
+
source: attendanceShape.source.default('manual'),
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
export const nestedCreateAttendanceBody = z.strictObject({
|
|
84
|
+
person_id: z.string().min(1),
|
|
85
|
+
status: z.enum(ATTENDANCE_STATUSES).default('registered'),
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
export const updateAttendanceBody = z.strictObject({ status: z.enum(ATTENDANCE_STATUSES) }).partial()
|
|
89
|
+
|
|
90
|
+
export interface EventsRoutesDependencies extends CredentialDependencies {
|
|
91
|
+
readonly events: EventsService
|
|
92
|
+
readonly attendances: AttendancesService
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function toAssociation(body: z.infer<typeof associationBody>): AssociationRef {
|
|
96
|
+
return { targetType: body.target_type, targetId: body.target_id }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function toCreateEventInput(body: z.infer<typeof createEventBody>): CreateEventInput {
|
|
100
|
+
return {
|
|
101
|
+
name: body.name,
|
|
102
|
+
kind: body.kind,
|
|
103
|
+
startsAt: new Date(body.starts_at),
|
|
104
|
+
endsAt: new Date(body.ends_at),
|
|
105
|
+
timezone: body.timezone,
|
|
106
|
+
location: body.location,
|
|
107
|
+
meetingUrl: body.meeting_url,
|
|
108
|
+
format: body.format,
|
|
109
|
+
details: body.details,
|
|
110
|
+
status: body.status,
|
|
111
|
+
ownerId: body.owner_id,
|
|
112
|
+
summary: body.summary,
|
|
113
|
+
tags: body.tags,
|
|
114
|
+
associations: body.associations.map(toAssociation),
|
|
115
|
+
customFields: body.custom_fields,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function toUpdateEventInput(body: z.infer<typeof updateEventBody>): UpdateEventInput {
|
|
120
|
+
return {
|
|
121
|
+
...(body.name === undefined ? {} : { name: body.name }),
|
|
122
|
+
...(body.kind === undefined ? {} : { kind: body.kind }),
|
|
123
|
+
...(body.starts_at === undefined ? {} : { startsAt: new Date(body.starts_at) }),
|
|
124
|
+
...(body.ends_at === undefined ? {} : { endsAt: new Date(body.ends_at) }),
|
|
125
|
+
...(body.timezone === undefined ? {} : { timezone: body.timezone }),
|
|
126
|
+
...(body.location === undefined ? {} : { location: body.location }),
|
|
127
|
+
...(body.meeting_url === undefined ? {} : { meetingUrl: body.meeting_url }),
|
|
128
|
+
...(body.format === undefined ? {} : { format: body.format }),
|
|
129
|
+
...(body.details === undefined ? {} : { details: body.details }),
|
|
130
|
+
...(body.status === undefined ? {} : { status: body.status }),
|
|
131
|
+
...(body.owner_id === undefined ? {} : { ownerId: body.owner_id }),
|
|
132
|
+
...(body.summary === undefined ? {} : { summary: body.summary }),
|
|
133
|
+
...(body.tags === undefined ? {} : { tags: body.tags }),
|
|
134
|
+
...(body.associations === undefined
|
|
135
|
+
? {}
|
|
136
|
+
: { associations: body.associations.map(toAssociation) }),
|
|
137
|
+
...(body.custom_fields === undefined ? {} : { customFields: body.custom_fields }),
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function eventResponse(event: EventView): Record<string, unknown> {
|
|
142
|
+
return {
|
|
143
|
+
id: event.id,
|
|
144
|
+
name: event.name,
|
|
145
|
+
kind: event.kind,
|
|
146
|
+
starts_at: event.startsAt.toISOString(),
|
|
147
|
+
ends_at: event.endsAt.toISOString(),
|
|
148
|
+
timezone: event.timezone,
|
|
149
|
+
location: event.location,
|
|
150
|
+
meeting_url: event.meetingUrl,
|
|
151
|
+
format: event.format,
|
|
152
|
+
details: event.details,
|
|
153
|
+
status: event.status,
|
|
154
|
+
owner_id: event.ownerId,
|
|
155
|
+
summary: event.summary,
|
|
156
|
+
tags: event.tags,
|
|
157
|
+
associations: event.associations.map((row) => ({
|
|
158
|
+
target_type: row.targetType,
|
|
159
|
+
target_id: row.targetId,
|
|
160
|
+
})),
|
|
161
|
+
custom_fields: renderCustomFieldsForWire(event.customFields),
|
|
162
|
+
created_at: event.createdAt.toISOString(),
|
|
163
|
+
updated_at: event.updatedAt.toISOString(),
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function toCreateAttendanceInput(
|
|
168
|
+
body: z.infer<typeof createAttendanceBody>,
|
|
169
|
+
): CreateAttendanceInput {
|
|
170
|
+
return {
|
|
171
|
+
eventId: body.event_id,
|
|
172
|
+
personId: body.person_id,
|
|
173
|
+
status: body.status,
|
|
174
|
+
source: body.source,
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function toUpdateAttendanceInput(
|
|
179
|
+
body: z.infer<typeof updateAttendanceBody>,
|
|
180
|
+
): UpdateAttendanceInput {
|
|
181
|
+
return body.status === undefined ? {} : { status: body.status }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function attendanceResponse(row: AttendanceView): Record<string, unknown> {
|
|
185
|
+
return {
|
|
186
|
+
id: row.id,
|
|
187
|
+
event_id: row.eventId,
|
|
188
|
+
person_id: row.personId,
|
|
189
|
+
status: row.status,
|
|
190
|
+
source: row.source,
|
|
191
|
+
created_at: row.createdAt.toISOString(),
|
|
192
|
+
updated_at: row.updatedAt.toISOString(),
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function readEnumFilter<Value extends string>(
|
|
197
|
+
context: Context,
|
|
198
|
+
name: string,
|
|
199
|
+
allowed: readonly Value[],
|
|
200
|
+
): readonly Value[] | undefined {
|
|
201
|
+
const values = readIdFilter(context, name)
|
|
202
|
+
|
|
203
|
+
if (values === undefined) {
|
|
204
|
+
return undefined
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const unknown = values.filter((value) => !allowed.includes(value as Value))
|
|
208
|
+
|
|
209
|
+
if (unknown.length > 0) {
|
|
210
|
+
throw AppError.validationFailed(`"${name}" does not take ${unknown.join(', ')}`, [
|
|
211
|
+
{ field: name, message: `Expected one of ${allowed.join(', ')}` },
|
|
212
|
+
])
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return values as readonly Value[]
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function readTimestampQuery(context: Context, name: string): Date | undefined {
|
|
219
|
+
const raw = context.req.query(name)
|
|
220
|
+
|
|
221
|
+
if (raw === undefined || raw === '') {
|
|
222
|
+
return undefined
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const parsed = isoTimestamp.safeParse(raw)
|
|
226
|
+
|
|
227
|
+
if (!parsed.success) {
|
|
228
|
+
throw AppError.validationFailed(`"${name}" must be an ISO 8601 timestamp`, [
|
|
229
|
+
{ field: name, message: 'Use 2026-08-02T01:00:00.000Z' },
|
|
230
|
+
])
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return new Date(parsed.data)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function mountEventsRoutes(router: Hono, dependencies: EventsRoutesDependencies): void {
|
|
237
|
+
const requireActor = (context: Context): Promise<Actor> => resolveActorFrom(dependencies, context)
|
|
238
|
+
|
|
239
|
+
router.get('/events', async (context) => {
|
|
240
|
+
const page = await dependencies.events.list(
|
|
241
|
+
await requireActor(context),
|
|
242
|
+
{
|
|
243
|
+
term: context.req.query('q'),
|
|
244
|
+
statuses: readEnumFilter(context, 'status', EVENT_STATUSES),
|
|
245
|
+
formats: readEnumFilter(context, 'format', EVENT_FORMATS),
|
|
246
|
+
ownerIds: readIdFilter(context, 'owner_id'),
|
|
247
|
+
from: readTimestampQuery(context, 'from'),
|
|
248
|
+
to: readTimestampQuery(context, 'to'),
|
|
249
|
+
},
|
|
250
|
+
readListParameters(context),
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
return context.json(pageBody(page, eventResponse))
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
router.post('/events', async (context) => {
|
|
257
|
+
const body = await readJsonBody(context, createEventBody)
|
|
258
|
+
const event = await dependencies.events.create(
|
|
259
|
+
await requireActor(context),
|
|
260
|
+
toCreateEventInput(body),
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
return context.json(eventResponse(event), 201)
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
router.get('/events/:id', async (context) => {
|
|
267
|
+
const event = await dependencies.events.get(
|
|
268
|
+
await requireActor(context),
|
|
269
|
+
context.req.param('id'),
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
return context.json(eventResponse(event))
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
router.patch('/events/:id', async (context) => {
|
|
276
|
+
const body = await readJsonBody(context, updateEventBody)
|
|
277
|
+
const event = await dependencies.events.update(
|
|
278
|
+
await requireActor(context),
|
|
279
|
+
context.req.param('id'),
|
|
280
|
+
toUpdateEventInput(body),
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
return context.json(eventResponse(event))
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
router.delete('/events/:id', async (context) => {
|
|
287
|
+
await dependencies.events.remove(await requireActor(context), context.req.param('id'))
|
|
288
|
+
|
|
289
|
+
return context.body(null, 204)
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
router.get('/events/:id/attendances', async (context) => {
|
|
293
|
+
const page = await dependencies.attendances.list(
|
|
294
|
+
await requireActor(context),
|
|
295
|
+
{
|
|
296
|
+
eventIds: [context.req.param('id')],
|
|
297
|
+
statuses: readEnumFilter(context, 'status', ATTENDANCE_STATUSES),
|
|
298
|
+
},
|
|
299
|
+
readListParameters(context),
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
return context.json(pageBody(page, attendanceResponse))
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
router.post('/events/:id/attendances', async (context) => {
|
|
306
|
+
const body = await readJsonBody(context, nestedCreateAttendanceBody)
|
|
307
|
+
const row = await dependencies.attendances.create(await requireActor(context), {
|
|
308
|
+
eventId: context.req.param('id'),
|
|
309
|
+
personId: body.person_id,
|
|
310
|
+
status: body.status,
|
|
311
|
+
source: 'manual',
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
return context.json(attendanceResponse(row), 201)
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
router.get('/attendances', async (context) => {
|
|
318
|
+
const page = await dependencies.attendances.list(
|
|
319
|
+
await requireActor(context),
|
|
320
|
+
{
|
|
321
|
+
eventIds: readIdFilter(context, 'event_id'),
|
|
322
|
+
personIds: readIdFilter(context, 'person_id'),
|
|
323
|
+
statuses: readEnumFilter(context, 'status', ATTENDANCE_STATUSES),
|
|
324
|
+
},
|
|
325
|
+
readListParameters(context),
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
return context.json(pageBody(page, attendanceResponse))
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
router.post('/attendances', async (context) => {
|
|
332
|
+
const body = await readJsonBody(context, createAttendanceBody)
|
|
333
|
+
const row = await dependencies.attendances.create(
|
|
334
|
+
await requireActor(context),
|
|
335
|
+
toCreateAttendanceInput(body),
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
return context.json(attendanceResponse(row), 201)
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
router.get('/attendances/:id', async (context) => {
|
|
342
|
+
const row = await dependencies.attendances.get(
|
|
343
|
+
await requireActor(context),
|
|
344
|
+
context.req.param('id'),
|
|
345
|
+
)
|
|
346
|
+
|
|
347
|
+
return context.json(attendanceResponse(row))
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
router.patch('/attendances/:id', async (context) => {
|
|
351
|
+
const body = await readJsonBody(context, updateAttendanceBody)
|
|
352
|
+
const row = await dependencies.attendances.update(
|
|
353
|
+
await requireActor(context),
|
|
354
|
+
context.req.param('id'),
|
|
355
|
+
toUpdateAttendanceInput(body),
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
return context.json(attendanceResponse(row))
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
router.delete('/attendances/:id', async (context) => {
|
|
362
|
+
await dependencies.attendances.remove(await requireActor(context), context.req.param('id'))
|
|
363
|
+
|
|
364
|
+
return context.body(null, 204)
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
router.get('/event-associations', async (context) => {
|
|
368
|
+
const actor = await requireActor(context)
|
|
369
|
+
const targetType = context.req.query('target_type')
|
|
370
|
+
const targetId = context.req.query('target_id')
|
|
371
|
+
|
|
372
|
+
if (targetType === undefined || targetId === undefined || targetId === '') {
|
|
373
|
+
throw AppError.validationFailed('target_type and target_id are required', [
|
|
374
|
+
{ field: 'target_type', message: 'Required with target_id' },
|
|
375
|
+
])
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const parsed = z.enum(EVENT_ASSOCIATION_TARGET_TYPES).safeParse(targetType)
|
|
379
|
+
|
|
380
|
+
if (!parsed.success) {
|
|
381
|
+
throw AppError.validationFailed('Unknown association target type', [
|
|
382
|
+
{
|
|
383
|
+
field: 'target_type',
|
|
384
|
+
message: `Use one of: ${EVENT_ASSOCIATION_TARGET_TYPES.join(', ')}`,
|
|
385
|
+
},
|
|
386
|
+
])
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const rows = await dependencies.events.listAssociationsFor(
|
|
390
|
+
actor,
|
|
391
|
+
parsed.data as EventAssociationTargetType,
|
|
392
|
+
targetId,
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
return context.json({
|
|
396
|
+
data: rows.map((row) => ({
|
|
397
|
+
event_id: row.eventId,
|
|
398
|
+
event_name: row.eventName,
|
|
399
|
+
target_type: parsed.data,
|
|
400
|
+
target_id: targetId,
|
|
401
|
+
})),
|
|
402
|
+
next_cursor: null,
|
|
403
|
+
})
|
|
404
|
+
})
|
|
405
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ATTENDANCE_SOURCES,
|
|
3
|
+
ATTENDANCE_STATUSES,
|
|
4
|
+
EVENT_ASSOCIATION_TARGET_TYPES,
|
|
5
|
+
EVENT_FORMATS,
|
|
6
|
+
EVENT_STATUSES,
|
|
7
|
+
} from '@kelpie/schemas'
|
|
8
|
+
import type { CustomFieldValue } from '@kelpie/schemas'
|
|
9
|
+
import { index, jsonb, pgTable, text, timestamp, unique } from 'drizzle-orm/pg-core'
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
checkOneOf,
|
|
13
|
+
createdAt,
|
|
14
|
+
primaryId,
|
|
15
|
+
searchVector,
|
|
16
|
+
updatedAt,
|
|
17
|
+
} from '../../lib/columns.ts'
|
|
18
|
+
import type { SearchVectorPart } from '../../lib/columns.ts'
|
|
19
|
+
import { people } from '../people/schema.ts'
|
|
20
|
+
import { workspaceMembers, workspaces } from '../workspace/schema.ts'
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
ATTENDANCE_SOURCES,
|
|
24
|
+
ATTENDANCE_STATUSES,
|
|
25
|
+
EVENT_ASSOCIATION_TARGET_TYPES,
|
|
26
|
+
EVENT_FORMATS,
|
|
27
|
+
EVENT_STATUSES,
|
|
28
|
+
} from '@kelpie/schemas'
|
|
29
|
+
export type {
|
|
30
|
+
AttendanceSource,
|
|
31
|
+
AttendanceStatus,
|
|
32
|
+
EventAssociationTargetType,
|
|
33
|
+
EventFormat,
|
|
34
|
+
EventStatus,
|
|
35
|
+
} from '@kelpie/schemas'
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A dated gathering. Not a pipeline: no stages, no kanban, no person_links.
|
|
39
|
+
* People attach as Attendances; other records attach through event_associations.
|
|
40
|
+
*/
|
|
41
|
+
export const events = pgTable(
|
|
42
|
+
'events',
|
|
43
|
+
{
|
|
44
|
+
id: primaryId(),
|
|
45
|
+
workspaceId: text('workspace_id')
|
|
46
|
+
.notNull()
|
|
47
|
+
.references(() => workspaces.id, { onDelete: 'cascade' }),
|
|
48
|
+
name: text('name').notNull(),
|
|
49
|
+
kind: text('kind').notNull().default(''),
|
|
50
|
+
startsAt: timestamp('starts_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
51
|
+
endsAt: timestamp('ends_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
52
|
+
timezone: text('timezone').notNull(),
|
|
53
|
+
location: text('location').notNull().default(''),
|
|
54
|
+
meetingUrl: text('meeting_url'),
|
|
55
|
+
format: text('format').notNull(),
|
|
56
|
+
details: text('details').notNull().default(''),
|
|
57
|
+
status: text('status').notNull(),
|
|
58
|
+
ownerId: text('owner_id').references(() => workspaceMembers.id, { onDelete: 'restrict' }),
|
|
59
|
+
summary: text('summary').notNull().default(''),
|
|
60
|
+
tags: text('tags').array().notNull().default([]),
|
|
61
|
+
customFields: jsonb('custom_fields')
|
|
62
|
+
.$type<Readonly<Record<string, CustomFieldValue>>>()
|
|
63
|
+
.notNull()
|
|
64
|
+
.default({}),
|
|
65
|
+
createdAt: createdAt(),
|
|
66
|
+
updatedAt: updatedAt(),
|
|
67
|
+
searchVector: searchVector((): readonly SearchVectorPart[] => [
|
|
68
|
+
{ column: events.name, weight: 'A' },
|
|
69
|
+
{ column: events.details, weight: 'B' },
|
|
70
|
+
{ column: events.summary, weight: 'B' },
|
|
71
|
+
{ column: events.kind, weight: 'C' },
|
|
72
|
+
{ column: events.location, weight: 'C' },
|
|
73
|
+
{ column: events.tags, weight: 'C', array: true },
|
|
74
|
+
]),
|
|
75
|
+
},
|
|
76
|
+
(table) => [
|
|
77
|
+
index('events_workspace_idx').on(table.workspaceId),
|
|
78
|
+
index('events_starts_idx').on(table.workspaceId, table.startsAt),
|
|
79
|
+
index('events_search_idx').using('gin', table.searchVector),
|
|
80
|
+
checkOneOf('events_format_check', table.format, EVENT_FORMATS),
|
|
81
|
+
checkOneOf('events_status_check', table.status, EVENT_STATUSES),
|
|
82
|
+
],
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
/** The Person↔Event link. RSVP state lives here, never on Person. */
|
|
86
|
+
export const attendances = pgTable(
|
|
87
|
+
'attendances',
|
|
88
|
+
{
|
|
89
|
+
id: primaryId(),
|
|
90
|
+
workspaceId: text('workspace_id')
|
|
91
|
+
.notNull()
|
|
92
|
+
.references(() => workspaces.id, { onDelete: 'cascade' }),
|
|
93
|
+
eventId: text('event_id')
|
|
94
|
+
.notNull()
|
|
95
|
+
.references(() => events.id, { onDelete: 'cascade' }),
|
|
96
|
+
personId: text('person_id')
|
|
97
|
+
.notNull()
|
|
98
|
+
.references(() => people.id, { onDelete: 'cascade' }),
|
|
99
|
+
status: text('status').notNull(),
|
|
100
|
+
source: text('source').notNull(),
|
|
101
|
+
createdAt: createdAt(),
|
|
102
|
+
updatedAt: updatedAt(),
|
|
103
|
+
},
|
|
104
|
+
(table) => [
|
|
105
|
+
unique('attendances_event_person_key').on(table.eventId, table.personId),
|
|
106
|
+
index('attendances_workspace_idx').on(table.workspaceId),
|
|
107
|
+
index('attendances_event_idx').on(table.eventId),
|
|
108
|
+
index('attendances_person_idx').on(table.personId),
|
|
109
|
+
checkOneOf('attendances_status_check', table.status, ATTENDANCE_STATUSES),
|
|
110
|
+
checkOneOf('attendances_source_check', table.source, ATTENDANCE_SOURCES),
|
|
111
|
+
],
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Event↔other record. Polymorphic target, no FK. The id never crosses the wire.
|
|
116
|
+
*/
|
|
117
|
+
export const eventAssociations = pgTable(
|
|
118
|
+
'event_associations',
|
|
119
|
+
{
|
|
120
|
+
id: primaryId(),
|
|
121
|
+
workspaceId: text('workspace_id')
|
|
122
|
+
.notNull()
|
|
123
|
+
.references(() => workspaces.id, { onDelete: 'cascade' }),
|
|
124
|
+
eventId: text('event_id')
|
|
125
|
+
.notNull()
|
|
126
|
+
.references(() => events.id, { onDelete: 'cascade' }),
|
|
127
|
+
targetType: text('target_type').notNull(),
|
|
128
|
+
targetId: text('target_id').notNull(),
|
|
129
|
+
createdAt: createdAt(),
|
|
130
|
+
},
|
|
131
|
+
(table) => [
|
|
132
|
+
unique('event_associations_event_target_key').on(
|
|
133
|
+
table.eventId,
|
|
134
|
+
table.targetType,
|
|
135
|
+
table.targetId,
|
|
136
|
+
),
|
|
137
|
+
index('event_associations_target_idx').on(
|
|
138
|
+
table.workspaceId,
|
|
139
|
+
table.targetType,
|
|
140
|
+
table.targetId,
|
|
141
|
+
),
|
|
142
|
+
checkOneOf(
|
|
143
|
+
'event_associations_target_type_check',
|
|
144
|
+
table.targetType,
|
|
145
|
+
EVENT_ASSOCIATION_TARGET_TYPES,
|
|
146
|
+
),
|
|
147
|
+
],
|
|
148
|
+
)
|