@hintergrund/worker 0.3.18 → 0.3.19
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/api/appointments/admin.d.ts +171 -0
- package/dist/api/appointments/admin.d.ts.map +1 -0
- package/dist/api/appointments/admin.js +275 -0
- package/dist/api/appointments/core.d.ts +114 -0
- package/dist/api/appointments/core.d.ts.map +1 -0
- package/dist/api/appointments/core.js +208 -0
- package/dist/api/appointments/cron.d.ts +9 -0
- package/dist/api/appointments/cron.d.ts.map +1 -0
- package/dist/api/appointments/cron.js +71 -0
- package/dist/api/appointments/emails.d.ts +5 -0
- package/dist/api/appointments/emails.d.ts.map +1 -0
- package/dist/api/appointments/emails.js +53 -0
- package/dist/api/appointments/public.d.ts +104 -0
- package/dist/api/appointments/public.d.ts.map +1 -0
- package/dist/api/appointments/public.js +129 -0
- package/dist/api/appointments/routes.d.ts +7 -0
- package/dist/api/appointments/routes.d.ts.map +1 -0
- package/dist/api/appointments/routes.js +28 -0
- package/dist/api/cms/handlers/agent-provider.handler.d.ts +0 -2
- package/dist/api/cms/handlers/agent-provider.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/agent-provider.handler.js +5 -10
- package/dist/api/cms/handlers/github-secrets.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/github-secrets.handler.js +3 -17
- package/dist/api/cms/handlers/integrations.handler.d.ts +2 -2
- package/dist/api/cms/handlers/integrations.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/integrations.handler.js +5 -11
- package/dist/api/cms/handlers/runtime.handler.d.ts +6 -0
- package/dist/api/cms/handlers/runtime.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/runtime.handler.js +42 -0
- package/dist/api/cms/handlers/website-repo.handler.d.ts +2 -0
- package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/website-repo.handler.js +31 -14
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/cms/routes/index.js +6 -6
- package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -6
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/campaigns.handler.js +127 -30
- package/dist/api/emails/handlers/public.handler.d.ts +0 -2
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/public.handler.js +32 -77
- package/dist/api/emails/handlers/send.handler.js +2 -2
- package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/subscribers.handler.js +9 -0
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/admin.routes.js +3 -1
- package/dist/api/emails/routes/mail.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/mail.routes.js +19 -17
- package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/public.routes.js +1 -2
- package/dist/api/enquiries/routes.d.ts +7 -0
- package/dist/api/enquiries/routes.d.ts.map +1 -0
- package/dist/api/enquiries/routes.js +73 -0
- package/dist/api/members/handlers.d.ts +36 -0
- package/dist/api/members/handlers.d.ts.map +1 -0
- package/dist/api/members/handlers.js +322 -0
- package/dist/api/members/routes.d.ts +5 -0
- package/dist/api/members/routes.d.ts.map +1 -0
- package/dist/api/members/routes.js +20 -0
- package/dist/api/reservations/core.d.ts +25 -0
- package/dist/api/reservations/core.d.ts.map +1 -0
- package/dist/api/reservations/core.js +59 -0
- package/dist/api/reservations/mail.d.ts +7 -0
- package/dist/api/reservations/mail.d.ts.map +1 -0
- package/dist/api/reservations/mail.js +63 -0
- package/dist/api/reservations/routes.d.ts +7 -0
- package/dist/api/reservations/routes.d.ts.map +1 -0
- package/dist/api/reservations/routes.js +186 -0
- package/dist/api/shop/handlers/products.handler.d.ts +1 -1
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/products.handler.js +3 -3
- package/dist/api/shop/handlers/public.handler.d.ts +3 -3
- package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/public.handler.js +25 -28
- package/dist/api/shop/routes.d.ts +2 -4
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +8 -11
- package/dist/api/stays/actions.d.ts +13 -0
- package/dist/api/stays/actions.d.ts.map +1 -0
- package/dist/api/stays/actions.js +28 -0
- package/dist/api/stays/admin.d.ts +209 -0
- package/dist/api/stays/admin.d.ts.map +1 -0
- package/dist/api/stays/admin.js +228 -0
- package/dist/api/stays/bookings.d.ts +113 -0
- package/dist/api/stays/bookings.d.ts.map +1 -0
- package/dist/api/stays/bookings.js +254 -0
- package/dist/api/stays/core.d.ts +214 -0
- package/dist/api/stays/core.d.ts.map +1 -0
- package/dist/api/stays/core.js +361 -0
- package/dist/api/stays/cron.d.ts +7 -0
- package/dist/api/stays/cron.d.ts.map +1 -0
- package/dist/api/stays/cron.js +56 -0
- package/dist/api/stays/mail.d.ts +8 -0
- package/dist/api/stays/mail.d.ts.map +1 -0
- package/dist/api/stays/mail.js +50 -0
- package/dist/api/stays/offers.d.ts +27 -0
- package/dist/api/stays/offers.d.ts.map +1 -0
- package/dist/api/stays/offers.js +56 -0
- package/dist/api/stays/payments.d.ts +47 -0
- package/dist/api/stays/payments.d.ts.map +1 -0
- package/dist/api/stays/payments.js +148 -0
- package/dist/api/stays/public.d.ts +207 -0
- package/dist/api/stays/public.d.ts.map +1 -0
- package/dist/api/stays/public.js +137 -0
- package/dist/api/stays/routes.d.ts +7 -0
- package/dist/api/stays/routes.d.ts.map +1 -0
- package/dist/api/stays/routes.js +39 -0
- package/dist/api/stripe/webhook.d.ts +5 -0
- package/dist/api/stripe/webhook.d.ts.map +1 -0
- package/dist/api/stripe/webhook.js +45 -0
- package/dist/api/tickets/core.d.ts +40 -0
- package/dist/api/tickets/core.d.ts.map +1 -0
- package/dist/api/tickets/core.js +115 -0
- package/dist/api/tickets/routes.d.ts +5 -0
- package/dist/api/tickets/routes.d.ts.map +1 -0
- package/dist/api/tickets/routes.js +70 -0
- package/dist/index.d.ts +14 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -27
- package/dist/lib/appointments-schema.d.ts +6 -0
- package/dist/lib/appointments-schema.d.ts.map +1 -0
- package/dist/lib/appointments-schema.js +96 -0
- package/dist/lib/config.js +4 -4
- package/dist/lib/email-template.d.ts +2 -2
- package/dist/lib/email-template.d.ts.map +1 -1
- package/dist/lib/email-template.js +3 -3
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +12 -3
- package/dist/lib/features.d.ts +13 -0
- package/dist/lib/features.d.ts.map +1 -0
- package/dist/lib/features.js +19 -0
- package/dist/lib/mail-schema.d.ts +1 -1
- package/dist/lib/mail-schema.d.ts.map +1 -1
- package/dist/lib/mail-schema.js +0 -1
- package/dist/lib/mail.d.ts +23 -3
- package/dist/lib/mail.d.ts.map +1 -1
- package/dist/lib/mail.js +69 -23
- package/dist/lib/members.d.ts +41 -0
- package/dist/lib/members.d.ts.map +1 -0
- package/dist/lib/members.js +92 -0
- package/dist/lib/project-db.d.ts +1 -1
- package/dist/lib/project-db.d.ts.map +1 -1
- package/dist/lib/project-db.js +67 -8
- package/dist/lib/reservations-schema.d.ts +3 -0
- package/dist/lib/reservations-schema.d.ts.map +1 -0
- package/dist/lib/reservations-schema.js +35 -0
- package/dist/lib/stays-schema.d.ts +3 -0
- package/dist/lib/stays-schema.d.ts.map +1 -0
- package/dist/lib/stays-schema.js +247 -0
- package/dist/lib/stripe.d.ts +6 -0
- package/dist/lib/stripe.d.ts.map +1 -0
- package/dist/lib/stripe.js +9 -0
- package/dist/lib/template.d.ts +2 -1
- package/dist/lib/template.d.ts.map +1 -1
- package/dist/lib/template.js +4 -82
- package/dist/lib/user-recovery.d.ts.map +1 -1
- package/dist/lib/user-recovery.js +4 -2
- package/dist/lib/website-i18n.d.ts +17 -0
- package/dist/lib/website-i18n.d.ts.map +1 -1
- package/dist/lib/website-i18n.js +36 -3
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +8 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/package.json +2 -2
- package/dist/api/cms/handlers/setup.handler.d.ts +0 -8
- package/dist/api/cms/handlers/setup.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/setup.handler.js +0 -278
- package/dist/lib/integration-health.d.ts +0 -15
- package/dist/lib/integration-health.d.ts.map +0 -1
- package/dist/lib/integration-health.js +0 -60
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { type BookingStatus } from '@hintergrund/runtime-contracts';
|
|
3
|
+
import type { Bindings } from '../../index';
|
|
4
|
+
type C = Context<{
|
|
5
|
+
Bindings: Bindings;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function getConfig(c: C): Promise<Response & import("hono").TypedResponse<{
|
|
8
|
+
timezone: string;
|
|
9
|
+
resources: {
|
|
10
|
+
id: string;
|
|
11
|
+
kind: "person" | "room";
|
|
12
|
+
name: string;
|
|
13
|
+
active: number;
|
|
14
|
+
}[];
|
|
15
|
+
rules: {
|
|
16
|
+
id: string;
|
|
17
|
+
resource_id: string;
|
|
18
|
+
weekday: number;
|
|
19
|
+
start_min: number;
|
|
20
|
+
end_min: number;
|
|
21
|
+
}[];
|
|
22
|
+
overrides: {
|
|
23
|
+
id: string;
|
|
24
|
+
resource_id: string;
|
|
25
|
+
date: string;
|
|
26
|
+
start_min: number | null;
|
|
27
|
+
end_min: number | null;
|
|
28
|
+
}[];
|
|
29
|
+
blocks: {
|
|
30
|
+
id: string;
|
|
31
|
+
resource_id: string;
|
|
32
|
+
starts_at: number;
|
|
33
|
+
ends_at: number;
|
|
34
|
+
note: string;
|
|
35
|
+
}[];
|
|
36
|
+
schedules: {
|
|
37
|
+
id: string;
|
|
38
|
+
offering_id: string;
|
|
39
|
+
weekday: number;
|
|
40
|
+
start_min: number;
|
|
41
|
+
teacher_id: string | null;
|
|
42
|
+
room_id: string | null;
|
|
43
|
+
valid_from: string;
|
|
44
|
+
valid_to: string;
|
|
45
|
+
}[];
|
|
46
|
+
products: {
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
credits: number;
|
|
50
|
+
validity_days: number;
|
|
51
|
+
price_cents: number;
|
|
52
|
+
active: number;
|
|
53
|
+
shop_product_id: string | null;
|
|
54
|
+
}[];
|
|
55
|
+
offerings: {
|
|
56
|
+
id: string;
|
|
57
|
+
kind: import("@hintergrund/runtime-contracts").AppointmentKind;
|
|
58
|
+
name: string;
|
|
59
|
+
description: string;
|
|
60
|
+
duration_min: number;
|
|
61
|
+
buffer_before_min: number;
|
|
62
|
+
buffer_after_min: number;
|
|
63
|
+
slot_interval_min: number;
|
|
64
|
+
capacity: number;
|
|
65
|
+
price_cents: number;
|
|
66
|
+
min_notice_min: number;
|
|
67
|
+
horizon_days: number;
|
|
68
|
+
cancel_cutoff_min: number;
|
|
69
|
+
requires_approval: number;
|
|
70
|
+
audience: import("@hintergrund/runtime-contracts").AppointmentAudience;
|
|
71
|
+
waitlist_lock_min: number | null;
|
|
72
|
+
active: number;
|
|
73
|
+
sort: number;
|
|
74
|
+
resource_ids: string[];
|
|
75
|
+
}[];
|
|
76
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">>;
|
|
77
|
+
export declare function putSettings(c: C): Promise<(Response & import("hono").TypedResponse<{
|
|
78
|
+
error: string;
|
|
79
|
+
}, 400, "json">) | (Response & import("hono").TypedResponse<{
|
|
80
|
+
ok: true;
|
|
81
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">)>;
|
|
82
|
+
export declare function createEntity(c: C): Promise<Response>;
|
|
83
|
+
export declare function updateEntity(c: C): Promise<Response>;
|
|
84
|
+
export declare function deleteEntity(c: C): Promise<Response>;
|
|
85
|
+
/** Sessions overlapping [from, to) with their people and bookings (cancelled ones left out). `pending` limits to the approval queue. */
|
|
86
|
+
export declare function calendar(c: C): Promise<Response & import("hono").TypedResponse<{
|
|
87
|
+
sessions: {
|
|
88
|
+
resource_ids: string[];
|
|
89
|
+
bookings: {
|
|
90
|
+
id: string;
|
|
91
|
+
status: BookingStatus;
|
|
92
|
+
customer_name: string;
|
|
93
|
+
customer_email: string;
|
|
94
|
+
customer_phone: string;
|
|
95
|
+
pass_id: string | null;
|
|
96
|
+
patient_type: import("@hintergrund/runtime-contracts").PatientType | null;
|
|
97
|
+
insurance: import("@hintergrund/runtime-contracts").InsuranceType | null;
|
|
98
|
+
created_at: number;
|
|
99
|
+
pass_remaining: number | null;
|
|
100
|
+
session_id: string;
|
|
101
|
+
}[];
|
|
102
|
+
status: "active" | "cancelled";
|
|
103
|
+
id: string;
|
|
104
|
+
offering_id: string;
|
|
105
|
+
capacity: number;
|
|
106
|
+
starts_at: number;
|
|
107
|
+
ends_at: number;
|
|
108
|
+
}[];
|
|
109
|
+
blocks: {
|
|
110
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
111
|
+
}[];
|
|
112
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">>;
|
|
113
|
+
export declare function manualBooking(c: C): Promise<(Response & import("hono").TypedResponse<{
|
|
114
|
+
error: string;
|
|
115
|
+
}, 400, "json">) | (Response & import("hono").TypedResponse<{
|
|
116
|
+
error: string;
|
|
117
|
+
}, 404, "json">) | (Response & import("hono").TypedResponse<{
|
|
118
|
+
error: string;
|
|
119
|
+
code: "invalid" | "full" | "not_found" | "slot_taken" | "already_booked" | "too_late";
|
|
120
|
+
}, 400 | 404 | 409, "json">) | (Response & import("hono").TypedResponse<{
|
|
121
|
+
id: string;
|
|
122
|
+
status: "pending" | "waitlisted" | "booked";
|
|
123
|
+
}, 201, "json">)>;
|
|
124
|
+
export declare function bookingAction(c: C): Promise<(Response & import("hono").TypedResponse<{
|
|
125
|
+
error: string;
|
|
126
|
+
}, 404, "json">) | (Response & import("hono").TypedResponse<{
|
|
127
|
+
error: string;
|
|
128
|
+
}, 409, "json">) | (Response & import("hono").TypedResponse<{
|
|
129
|
+
error: string;
|
|
130
|
+
}, 400, "json">) | (Response & import("hono").TypedResponse<{
|
|
131
|
+
ok: true;
|
|
132
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">)>;
|
|
133
|
+
/** Cancels a whole session (class called off) and tells everyone on it. */
|
|
134
|
+
export declare function cancelSession(c: C): Promise<Response & import("hono").TypedResponse<{
|
|
135
|
+
ok: true;
|
|
136
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">>;
|
|
137
|
+
export declare function series(c: C): Promise<(Response & import("hono").TypedResponse<{
|
|
138
|
+
error: string;
|
|
139
|
+
}, 400, "json">) | (Response & import("hono").TypedResponse<{
|
|
140
|
+
error: string;
|
|
141
|
+
}, 404, "json">) | (Response & import("hono").TypedResponse<{
|
|
142
|
+
warnings: string[];
|
|
143
|
+
starts: number[];
|
|
144
|
+
failed: number[];
|
|
145
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">)>;
|
|
146
|
+
export declare function listPasses(c: C): Promise<Response & import("hono").TypedResponse<{
|
|
147
|
+
passes: {
|
|
148
|
+
id: string;
|
|
149
|
+
name: string;
|
|
150
|
+
credits: number;
|
|
151
|
+
remaining: number;
|
|
152
|
+
expires_at: number;
|
|
153
|
+
customer_name: string;
|
|
154
|
+
customer_email: string;
|
|
155
|
+
}[];
|
|
156
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">>;
|
|
157
|
+
/** Staff grant a pass for a product (paid in person or by transfer). */
|
|
158
|
+
export declare function grantPass(c: C): Promise<(Response & import("hono").TypedResponse<{
|
|
159
|
+
error: string;
|
|
160
|
+
}, 400, "json">) | (Response & import("hono").TypedResponse<{
|
|
161
|
+
error: string;
|
|
162
|
+
}, 404, "json">) | (Response & import("hono").TypedResponse<{
|
|
163
|
+
ok: true;
|
|
164
|
+
}, 201, "json">)>;
|
|
165
|
+
export declare function deletePass(c: C): Promise<(Response & import("hono").TypedResponse<{
|
|
166
|
+
ok: true;
|
|
167
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
|
|
168
|
+
error: string;
|
|
169
|
+
}, 409, "json">)>;
|
|
170
|
+
export {};
|
|
171
|
+
//# sourceMappingURL=admin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../../src/api/appointments/admin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAiK,KAAK,aAAa,EAAsE,MAAM,gCAAgC,CAAC;AACvS,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQ5C,KAAK,CAAC,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC;AA6BzC,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mEAcnC;AAED,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC;;;;oEAOrC;AAeD,wBAAsB,YAAY,CAAC,CAAC,EAAE,CAAC,qBAWtC;AAED,wBAAsB,YAAY,CAAC,CAAC,EAAE,CAAC,qBActC;AAED,wBAAsB,YAAY,CAAC,CAAC,EAAE,CAAC,qBAStC;AAED,wIAAwI;AACxI,wBAAsB,QAAQ,CAAC,CAAC,EAAE,CAAC;;;;;;;;;;;;;;wBAcgB,MAAM;;;;;;;;;;;;mEAMxD;AAED,wBAAsB,aAAa,CAAC,CAAC,EAAE,CAAC;;;;;;;;;;kBAiBvC;AAUD,wBAAsB,aAAa,CAAC,CAAC,EAAE,CAAC;;;;;;;;oEAkBvC;AAED,2EAA2E;AAC3E,wBAAsB,aAAa,CAAC,CAAC,EAAE,CAAC;;mEAWvC;AAED,wBAAsB,MAAM,CAAC,CAAC,EAAE,CAAC;;;;;;;;oEAyBhC;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,CAAC;;;;;;;;;;mEAOpC;AAED,wEAAwE;AACxE,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC;;;;;;kBASnC;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,CAAC;;;;kBAIpC"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { addDays, localParts, seriesWarnings, zonedToUtc } from '@hintergrund/runtime-contracts';
|
|
2
|
+
import { creditsLeft } from '../../lib/appointments-schema';
|
|
3
|
+
import { createId, ensureSchema } from '../../lib/project-db';
|
|
4
|
+
import { validEmail } from '../../lib/user-recovery';
|
|
5
|
+
import { materialise } from './cron';
|
|
6
|
+
import { BOOKING_CONTEXT_SQL, passStatements, createBooking, endBooking, getSettings } from './core';
|
|
7
|
+
import { sendBookingEmails } from './emails';
|
|
8
|
+
const quiet = (promise) => promise.catch(error => console.error('Appointment email failed:', error));
|
|
9
|
+
/** Columns staff may write per table: s string, n integer, b flag, N nullable integer, S nullable string. */
|
|
10
|
+
const ENTITIES = {
|
|
11
|
+
resources: { table: 'appt_resources', cols: { kind: 's', name: 's', active: 'b' } },
|
|
12
|
+
offerings: { table: 'appt_offerings', cols: { kind: 's', name: 's', description: 's', duration_min: 'n', buffer_before_min: 'n', buffer_after_min: 'n', slot_interval_min: 'n', capacity: 'n', price_cents: 'n', min_notice_min: 'n', horizon_days: 'n', cancel_cutoff_min: 'n', requires_approval: 'b', audience: 's', waitlist_lock_min: 'N', active: 'b', sort: 'n' } },
|
|
13
|
+
rules: { table: 'appt_rules', cols: { resource_id: 's', weekday: 'n', start_min: 'n', end_min: 'n' } },
|
|
14
|
+
overrides: { table: 'appt_overrides', cols: { resource_id: 's', date: 's', start_min: 'N', end_min: 'N' } },
|
|
15
|
+
blocks: { table: 'appt_blocks', cols: { resource_id: 's', starts_at: 'n', ends_at: 'n', note: 's' } },
|
|
16
|
+
schedules: { table: 'appt_schedules', cols: { offering_id: 's', weekday: 'n', start_min: 'n', teacher_id: 'S', room_id: 'S', valid_from: 's', valid_to: 's' } },
|
|
17
|
+
products: { table: 'appt_products', cols: { name: 's', credits: 'n', validity_days: 'n', price_cents: 'n', active: 'b', shop_product_id: 's' } },
|
|
18
|
+
};
|
|
19
|
+
function fieldsOf(entity, body) {
|
|
20
|
+
const cols = ENTITIES[entity].cols;
|
|
21
|
+
return Object.entries(cols).filter(([key]) => key in body).map(([key, type]) => {
|
|
22
|
+
const value = body[key];
|
|
23
|
+
if (type === 'n' || type === 'b' || type === 'N') {
|
|
24
|
+
if (value === null && type === 'N')
|
|
25
|
+
return [key, null];
|
|
26
|
+
const number = type === 'b' ? (value ? 1 : 0) : Number(value);
|
|
27
|
+
if (!Number.isFinite(number))
|
|
28
|
+
throw new Error(`${key} must be a number.`);
|
|
29
|
+
return [key, Math.round(number)];
|
|
30
|
+
}
|
|
31
|
+
if (value === null && type === 'S')
|
|
32
|
+
return [key, null];
|
|
33
|
+
return [key, String(value ?? '').trim()];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export async function getConfig(c) {
|
|
37
|
+
const db = await ensureSchema(c.env);
|
|
38
|
+
const all = (sql) => db.prepare(sql).all().then(result => result.results);
|
|
39
|
+
const [settings, resources, offerings, links, rules, overrides, blocks, schedules, products] = await Promise.all([
|
|
40
|
+
getSettings(db), all('SELECT * FROM appt_resources ORDER BY kind, name'),
|
|
41
|
+
all('SELECT * FROM appt_offerings ORDER BY sort, name'), all('SELECT * FROM appt_offering_resources'),
|
|
42
|
+
all('SELECT * FROM appt_rules ORDER BY resource_id, weekday, start_min'),
|
|
43
|
+
all('SELECT * FROM appt_overrides ORDER BY date'), all(`SELECT * FROM appt_blocks WHERE ends_at > ${Date.now()} ORDER BY starts_at`), all('SELECT * FROM appt_schedules ORDER BY weekday, start_min'),
|
|
44
|
+
all('SELECT * FROM appt_products ORDER BY name'),
|
|
45
|
+
]);
|
|
46
|
+
return c.json({
|
|
47
|
+
timezone: settings.timezone, resources, rules, overrides, blocks, schedules, products,
|
|
48
|
+
offerings: offerings.map((offering) => ({ ...offering, resource_ids: links.filter(link => link.offering_id === offering.id).map(link => link.resource_id) })),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export async function putSettings(c) {
|
|
52
|
+
const { timezone } = await c.req.json().catch(() => ({}));
|
|
53
|
+
try {
|
|
54
|
+
new Intl.DateTimeFormat('en', { timeZone: timezone });
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return c.json({ error: 'Unknown time zone.' }, 400);
|
|
58
|
+
}
|
|
59
|
+
const db = await ensureSchema(c.env);
|
|
60
|
+
await getSettings(db);
|
|
61
|
+
await db.prepare('UPDATE appt_settings SET timezone = ? WHERE id = 1').bind(timezone).run();
|
|
62
|
+
return c.json({ ok: true });
|
|
63
|
+
}
|
|
64
|
+
async function saveLinks(db, offeringId, ids) {
|
|
65
|
+
if (!Array.isArray(ids))
|
|
66
|
+
return;
|
|
67
|
+
await db.batch([
|
|
68
|
+
db.prepare('DELETE FROM appt_offering_resources WHERE offering_id = ?').bind(offeringId),
|
|
69
|
+
...ids.map(id => db.prepare('INSERT INTO appt_offering_resources (offering_id, resource_id) VALUES (?, ?)').bind(offeringId, String(id))),
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
async function afterWrite(c, db, entity, id, body) {
|
|
73
|
+
if (entity === 'offerings')
|
|
74
|
+
await saveLinks(db, id, body.resource_ids);
|
|
75
|
+
if (entity === 'schedules' || entity === 'offerings')
|
|
76
|
+
await materialise(db, (await getSettings(db)).timezone, entity === 'schedules' ? { scheduleId: id } : { offeringId: id });
|
|
77
|
+
}
|
|
78
|
+
export async function createEntity(c) {
|
|
79
|
+
const entity = c.req.param('entity') ?? '';
|
|
80
|
+
if (!ENTITIES[entity])
|
|
81
|
+
return c.notFound();
|
|
82
|
+
const body = await c.req.json().catch(() => ({}));
|
|
83
|
+
const db = await ensureSchema(c.env);
|
|
84
|
+
try {
|
|
85
|
+
const fields = fieldsOf(entity, body), id = createId(entity.slice(0, 3));
|
|
86
|
+
await db.prepare(`INSERT INTO ${ENTITIES[entity].table} (id${fields.map(([key]) => `, ${key}`).join('')}) VALUES (?${fields.map(() => ', ?').join('')})`).bind(id, ...fields.map(([, value]) => value)).run();
|
|
87
|
+
await afterWrite(c, db, entity, id, body);
|
|
88
|
+
return c.json({ id }, 201);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return c.json({ error: error.message }, 400);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export async function updateEntity(c) {
|
|
95
|
+
const entity = c.req.param('entity') ?? '', id = c.req.param('id') ?? '';
|
|
96
|
+
if (!ENTITIES[entity])
|
|
97
|
+
return c.notFound();
|
|
98
|
+
const body = await c.req.json().catch(() => ({}));
|
|
99
|
+
const db = await ensureSchema(c.env);
|
|
100
|
+
try {
|
|
101
|
+
const fields = fieldsOf(entity, body);
|
|
102
|
+
if (fields.length) {
|
|
103
|
+
const result = await db.prepare(`UPDATE ${ENTITIES[entity].table} SET ${fields.map(([key]) => `${key} = ?`).join(', ')} WHERE id = ?`).bind(...fields.map(([, value]) => value), id).run();
|
|
104
|
+
if (!result.meta.changes)
|
|
105
|
+
return c.notFound();
|
|
106
|
+
}
|
|
107
|
+
await afterWrite(c, db, entity, id, body);
|
|
108
|
+
return c.json({ ok: true });
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return c.json({ error: error.message }, 400);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export async function deleteEntity(c) {
|
|
115
|
+
const entity = c.req.param('entity') ?? '', id = c.req.param('id') ?? '';
|
|
116
|
+
if (!ENTITIES[entity])
|
|
117
|
+
return c.notFound();
|
|
118
|
+
const db = await ensureSchema(c.env);
|
|
119
|
+
// A timetable entry that goes away takes its future, still empty sessions with it; booked ones stay.
|
|
120
|
+
if (entity === 'schedules')
|
|
121
|
+
await db.prepare('DELETE FROM appt_sessions WHERE schedule_id = ? AND starts_at > ? AND NOT EXISTS (SELECT 1 FROM appt_bookings WHERE session_id = appt_sessions.id)').bind(id, Date.now()).run();
|
|
122
|
+
try {
|
|
123
|
+
await db.prepare(`DELETE FROM ${ENTITIES[entity].table} WHERE id = ?`).bind(id).run();
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return c.json({ error: 'Still in use.' }, 409);
|
|
127
|
+
}
|
|
128
|
+
return c.json({ ok: true });
|
|
129
|
+
}
|
|
130
|
+
/** Sessions overlapping [from, to) with their people and bookings (cancelled ones left out). `pending` limits to the approval queue. */
|
|
131
|
+
export async function calendar(c) {
|
|
132
|
+
const db = await ensureSchema(c.env);
|
|
133
|
+
const from = Number(c.req.query('from')) || Date.now(), to = Number(c.req.query('to')) || from + 7 * 86400000;
|
|
134
|
+
const pending = c.req.query('pending') === '1';
|
|
135
|
+
const sessions = (await db.prepare(`SELECT s.id, s.offering_id, s.starts_at, s.ends_at, s.capacity, s.status, (SELECT group_concat(resource_id) FROM appt_session_resources WHERE session_id = s.id) AS resources
|
|
136
|
+
FROM appt_sessions s WHERE s.status = 'active' AND s.starts_at < ? AND s.ends_at > ?
|
|
137
|
+
${pending ? `AND EXISTS (SELECT 1 FROM appt_bookings WHERE session_id = s.id AND status = 'pending')` : ''} ORDER BY s.starts_at`).bind(to, from).all()).results;
|
|
138
|
+
const bookings = sessions.length ? (await db.prepare(`SELECT b.session_id, b.id, b.status, c.name AS customer_name, c.email AS customer_email, c.phone AS customer_phone, b.pass_id, b.patient_type, b.insurance, b.created_at,
|
|
139
|
+
CASE WHEN b.pass_id IS NULL THEN NULL ELSE ${creditsLeft('b.pass_id')} END AS pass_remaining
|
|
140
|
+
FROM appt_bookings b JOIN appt_customers c ON c.id = b.customer_id
|
|
141
|
+
WHERE b.status != 'cancelled' AND b.session_id IN (SELECT id FROM appt_sessions WHERE status = 'active' AND starts_at < ? AND ends_at > ?) ORDER BY b.created_at`).bind(to, from).all()).results : [];
|
|
142
|
+
const blocks = (await db.prepare('SELECT * FROM appt_blocks WHERE starts_at < ? AND ends_at > ? ORDER BY starts_at').bind(to, from).all()).results;
|
|
143
|
+
return c.json({
|
|
144
|
+
sessions: sessions.map(({ resources, ...session }) => ({ ...session, resource_ids: resources ? resources.split(',') : [], bookings: bookings.filter(booking => booking.session_id === session.id) })),
|
|
145
|
+
blocks,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
export async function manualBooking(c) {
|
|
149
|
+
const body = await c.req.json().catch(() => null);
|
|
150
|
+
const email = String(body?.email ?? '').trim().toLowerCase();
|
|
151
|
+
if (!body || !String(body.name ?? '').trim() || !validEmail(email))
|
|
152
|
+
return c.json({ error: 'Name and a valid email are required.' }, 400);
|
|
153
|
+
const db = await ensureSchema(c.env);
|
|
154
|
+
const { timezone } = await getSettings(db);
|
|
155
|
+
const offering = await db.prepare('SELECT * FROM appt_offerings WHERE id = ?').bind(body.offeringId ?? '').first();
|
|
156
|
+
if (!offering)
|
|
157
|
+
return c.json({ error: 'Offering not found.' }, 404);
|
|
158
|
+
const session = offering.kind === 'class' ? await db.prepare('SELECT * FROM appt_sessions WHERE id = ?').bind(body.sessionId ?? '').first() ?? undefined : undefined;
|
|
159
|
+
const result = await createBooking(c.env, db, timezone, {
|
|
160
|
+
offering, session, startsAt: body.startsAt, resourceId: body.resourceId, name: String(body.name).trim(), email, phone: String(body.phone ?? '').trim(),
|
|
161
|
+
patientType: body.patientType ?? null, insurance: body.insurance ?? null, consent: body.reminderConsent === true, usePass: body.usePass !== false,
|
|
162
|
+
locale: body.locale === 'de' ? 'de' : 'en', manual: true,
|
|
163
|
+
});
|
|
164
|
+
if (!result.ok)
|
|
165
|
+
return c.json({ error: result.error, code: result.code }, result.http);
|
|
166
|
+
if (body.notify !== false)
|
|
167
|
+
await quiet(sendBookingEmails(c.env, db, [result.id], result.status === 'waitlisted' ? 'waitlisted' : 'confirmed'));
|
|
168
|
+
return c.json({ id: result.id, status: result.status }, 201);
|
|
169
|
+
}
|
|
170
|
+
const TRANSITIONS = {
|
|
171
|
+
approve: { from: ['pending'], to: 'booked' },
|
|
172
|
+
attend: { from: ['booked', 'no_show'], to: 'attended' },
|
|
173
|
+
no_show: { from: ['booked', 'attended'], to: 'no_show' },
|
|
174
|
+
undo: { from: ['attended', 'no_show'], to: 'booked' },
|
|
175
|
+
promote: { from: ['waitlisted'], to: 'booked' },
|
|
176
|
+
};
|
|
177
|
+
export async function bookingAction(c) {
|
|
178
|
+
const { action } = await c.req.json().catch(() => ({}));
|
|
179
|
+
const db = await ensureSchema(c.env);
|
|
180
|
+
const booking = await db.prepare(`${BOOKING_CONTEXT_SQL} WHERE b.id = ?`).bind(c.req.param('id') ?? '').first();
|
|
181
|
+
if (!booking)
|
|
182
|
+
return c.json({ error: 'Booking not found.' }, 404);
|
|
183
|
+
const mail = { approve: 'approved', reject: 'rejected', cancel: 'cancelled', late_cancel: 'cancelled', promote: 'promoted' };
|
|
184
|
+
if (action === 'reject' || action === 'cancel' || action === 'late_cancel') {
|
|
185
|
+
if (!['pending', 'booked', 'waitlisted'].includes(booking.status))
|
|
186
|
+
return c.json({ error: 'Booking is not active.' }, 409);
|
|
187
|
+
await endBooking(c.env, db, booking, action === 'late_cancel' ? 'late_cancelled' : 'cancelled');
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const step = TRANSITIONS[action ?? ''];
|
|
191
|
+
if (!step)
|
|
192
|
+
return c.json({ error: 'Unknown action.' }, 400);
|
|
193
|
+
if (!step.from.includes(booking.status))
|
|
194
|
+
return c.json({ error: 'Booking is not in the right state.' }, 409);
|
|
195
|
+
try {
|
|
196
|
+
await db.prepare('UPDATE appt_bookings SET status = ?, updated_at = ? WHERE id = ? AND status = ?').bind(step.to, Date.now(), booking.id, booking.status).run();
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return c.json({ error: 'The class is full.', code: 'full' }, 409);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (mail[action])
|
|
203
|
+
await quiet(sendBookingEmails(c.env, db, [booking.id], mail[action]));
|
|
204
|
+
return c.json({ ok: true });
|
|
205
|
+
}
|
|
206
|
+
/** Cancels a whole session (class called off) and tells everyone on it. */
|
|
207
|
+
export async function cancelSession(c) {
|
|
208
|
+
const id = c.req.param('id') ?? '';
|
|
209
|
+
const db = await ensureSchema(c.env);
|
|
210
|
+
const ids = (await db.prepare(`SELECT id FROM appt_bookings WHERE session_id = ? AND status IN ('pending','booked','waitlisted')`).bind(id).all()).results.map(row => row.id);
|
|
211
|
+
await db.batch([
|
|
212
|
+
db.prepare(`UPDATE appt_bookings SET status = 'cancelled', updated_at = ? WHERE session_id = ? AND status IN ('pending','booked','waitlisted')`).bind(Date.now(), id),
|
|
213
|
+
db.prepare(`UPDATE appt_sessions SET status = 'cancelled' WHERE id = ?`).bind(id),
|
|
214
|
+
db.prepare('DELETE FROM appt_session_resources WHERE session_id = ?').bind(id),
|
|
215
|
+
]);
|
|
216
|
+
for (const bookingId of ids)
|
|
217
|
+
await quiet(sendBookingEmails(c.env, db, [bookingId], 'cancelled'));
|
|
218
|
+
return c.json({ ok: true });
|
|
219
|
+
}
|
|
220
|
+
export async function series(c) {
|
|
221
|
+
const body = await c.req.json().catch(() => null);
|
|
222
|
+
const email = String(body?.email ?? '').trim().toLowerCase();
|
|
223
|
+
const count = Math.round(Number(body?.count));
|
|
224
|
+
if (!body || !body.offeringId || !body.resourceId || !body.firstStartsAt || !(count >= 1 && count <= 52) || (!body.preview && (!String(body.name ?? '').trim() || !validEmail(email))))
|
|
225
|
+
return c.json({ error: 'Offering, person, first session, count (1–52) and, to book, name and email are required.' }, 400);
|
|
226
|
+
const db = await ensureSchema(c.env);
|
|
227
|
+
const { timezone } = await getSettings(db);
|
|
228
|
+
const offering = await db.prepare(`SELECT * FROM appt_offerings WHERE id = ? AND kind = 'appointment'`).bind(body.offeringId).first();
|
|
229
|
+
if (!offering)
|
|
230
|
+
return c.json({ error: 'Offering not found.' }, 404);
|
|
231
|
+
// Same local time every interval, also across a change of daylight saving time.
|
|
232
|
+
const { date, minutes } = localParts(body.firstStartsAt, timezone);
|
|
233
|
+
const starts = Array.from({ length: count }, (_, index) => zonedToUtc(addDays(date, index * Math.max(1, Math.round(Number(body.intervalDays)) || 7)), minutes, timezone));
|
|
234
|
+
const warnings = seriesWarnings(starts, timezone, body.prescriptionDate);
|
|
235
|
+
const failed = [], ids = [];
|
|
236
|
+
if (!body.preview) {
|
|
237
|
+
for (const startsAt of starts) {
|
|
238
|
+
const result = await createBooking(c.env, db, timezone, {
|
|
239
|
+
offering, startsAt, resourceId: body.resourceId, name: String(body.name).trim(), email, phone: String(body.phone ?? '').trim(),
|
|
240
|
+
patientType: null, insurance: body.insurance ?? null, consent: false, usePass: false, locale: body.locale === 'de' ? 'de' : 'en', manual: true,
|
|
241
|
+
});
|
|
242
|
+
if (result.ok)
|
|
243
|
+
ids.push(result.id);
|
|
244
|
+
else
|
|
245
|
+
failed.push(startsAt);
|
|
246
|
+
}
|
|
247
|
+
if (ids.length)
|
|
248
|
+
await quiet(sendBookingEmails(c.env, db, ids, 'confirmed'));
|
|
249
|
+
}
|
|
250
|
+
return c.json({ warnings, starts, failed });
|
|
251
|
+
}
|
|
252
|
+
export async function listPasses(c) {
|
|
253
|
+
const db = await ensureSchema(c.env);
|
|
254
|
+
const rows = await db.prepare(`SELECT p.id, p.name, p.credits, ${creditsLeft('p.id')} AS remaining, p.expires_at, c.name AS customer_name, c.email AS customer_email
|
|
255
|
+
FROM appt_passes p JOIN appt_customers c ON c.id = p.customer_id ORDER BY p.expires_at DESC LIMIT 300`).all();
|
|
256
|
+
return c.json({ passes: rows.results });
|
|
257
|
+
}
|
|
258
|
+
/** Staff grant a pass for a product (paid in person or by transfer). */
|
|
259
|
+
export async function grantPass(c) {
|
|
260
|
+
const body = await c.req.json().catch(() => ({}));
|
|
261
|
+
const email = String(body.email ?? '').trim().toLowerCase(), name = String(body.name ?? '').trim();
|
|
262
|
+
if (!name || !validEmail(email))
|
|
263
|
+
return c.json({ error: 'Name and a valid email are required.' }, 400);
|
|
264
|
+
const db = await ensureSchema(c.env);
|
|
265
|
+
const product = await db.prepare('SELECT * FROM appt_products WHERE id = ?').bind(body.productId ?? '').first();
|
|
266
|
+
if (!product)
|
|
267
|
+
return c.json({ error: 'Product not found.' }, 404);
|
|
268
|
+
await db.batch(passStatements(db, product, name, email));
|
|
269
|
+
return c.json({ ok: true }, 201);
|
|
270
|
+
}
|
|
271
|
+
export async function deletePass(c) {
|
|
272
|
+
const db = await ensureSchema(c.env);
|
|
273
|
+
const result = await db.prepare('DELETE FROM appt_passes WHERE id = ? AND NOT EXISTS (SELECT 1 FROM appt_bookings WHERE pass_id = appt_passes.id)').bind(c.req.param('id') ?? '').run();
|
|
274
|
+
return result.meta.changes ? c.json({ ok: true }) : c.json({ error: 'The pass has bookings and cannot be deleted.' }, 409);
|
|
275
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type ShopOrder, type AppointmentKind, type BookingStatus, type InsuranceType, type PatientType, type AppointmentLocale } from '@hintergrund/runtime-contracts';
|
|
2
|
+
import type { Bindings } from '../../index';
|
|
3
|
+
export declare const MIN = 60000;
|
|
4
|
+
export interface OfferingRow {
|
|
5
|
+
id: string;
|
|
6
|
+
kind: AppointmentKind;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
duration_min: number;
|
|
10
|
+
buffer_before_min: number;
|
|
11
|
+
buffer_after_min: number;
|
|
12
|
+
slot_interval_min: number;
|
|
13
|
+
capacity: number;
|
|
14
|
+
price_cents: number;
|
|
15
|
+
min_notice_min: number;
|
|
16
|
+
horizon_days: number;
|
|
17
|
+
cancel_cutoff_min: number;
|
|
18
|
+
requires_approval: number;
|
|
19
|
+
audience: 'all' | 'new' | 'returning';
|
|
20
|
+
waitlist_lock_min: number | null;
|
|
21
|
+
active: number;
|
|
22
|
+
sort: number;
|
|
23
|
+
}
|
|
24
|
+
export interface SessionRow {
|
|
25
|
+
id: string;
|
|
26
|
+
offering_id: string;
|
|
27
|
+
starts_at: number;
|
|
28
|
+
ends_at: number;
|
|
29
|
+
capacity: number;
|
|
30
|
+
status: 'active' | 'cancelled';
|
|
31
|
+
}
|
|
32
|
+
export interface Settings {
|
|
33
|
+
timezone: string;
|
|
34
|
+
origin: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function getSettings(db: D1Database, origin?: string, fallbackOrigin?: string): Promise<Settings>;
|
|
37
|
+
/**
|
|
38
|
+
* Bookable starts of an appointment offering between two local dates (inclusive), each with the
|
|
39
|
+
* people free for it: working hours (or the day's override) minus blocks and busy sessions,
|
|
40
|
+
* stepped by the slot interval, after the minimum notice and within the horizon.
|
|
41
|
+
*/
|
|
42
|
+
export declare function computeSlots(db: D1Database, offering: OfferingRow, resourceIds: string[], from: string, to: string, tz: string, now?: number): Promise<Map<number, string[]>>;
|
|
43
|
+
export declare function offeringResourceIds(db: D1Database, offeringId: string): Promise<string[]>;
|
|
44
|
+
export interface BookingInput {
|
|
45
|
+
offering: OfferingRow;
|
|
46
|
+
session?: SessionRow;
|
|
47
|
+
startsAt?: number;
|
|
48
|
+
resourceId?: string;
|
|
49
|
+
name: string;
|
|
50
|
+
email: string;
|
|
51
|
+
phone: string;
|
|
52
|
+
patientType: PatientType | null;
|
|
53
|
+
insurance: InsuranceType | null;
|
|
54
|
+
consent: boolean;
|
|
55
|
+
usePass: boolean;
|
|
56
|
+
locale: AppointmentLocale;
|
|
57
|
+
/** Staff booking: skips notice, horizon, audience, approval and working hours. Never the overlap or capacity triggers. */
|
|
58
|
+
manual: boolean;
|
|
59
|
+
status?: BookingStatus;
|
|
60
|
+
}
|
|
61
|
+
export type BookingResult = {
|
|
62
|
+
ok: true;
|
|
63
|
+
id: string;
|
|
64
|
+
token: string;
|
|
65
|
+
status: 'booked' | 'pending' | 'waitlisted';
|
|
66
|
+
startsAt: number;
|
|
67
|
+
endsAt: number;
|
|
68
|
+
payment?: 'pass' | 'dropin';
|
|
69
|
+
} | {
|
|
70
|
+
ok: false;
|
|
71
|
+
http: 400 | 404 | 409;
|
|
72
|
+
code: 'invalid' | 'not_found' | 'slot_taken' | 'full' | 'already_booked' | 'too_late';
|
|
73
|
+
error: string;
|
|
74
|
+
};
|
|
75
|
+
/** Creates one appointment or class seat. A conflict rolls the batch back and surfaces as 409. */
|
|
76
|
+
export declare function createBooking(env: Bindings, db: D1Database, tz: string, input: BookingInput): Promise<BookingResult>;
|
|
77
|
+
export interface BookingContext {
|
|
78
|
+
id: string;
|
|
79
|
+
status: BookingStatus;
|
|
80
|
+
session_id: string;
|
|
81
|
+
cancel_token: string;
|
|
82
|
+
locale: AppointmentLocale;
|
|
83
|
+
pass_id: string | null;
|
|
84
|
+
starts_at: number;
|
|
85
|
+
ends_at: number;
|
|
86
|
+
session_status: string;
|
|
87
|
+
offering_id: string;
|
|
88
|
+
kind: AppointmentKind;
|
|
89
|
+
offering_name: string;
|
|
90
|
+
cancel_cutoff_min: number;
|
|
91
|
+
waitlist_lock_min: number | null;
|
|
92
|
+
name: string;
|
|
93
|
+
email: string;
|
|
94
|
+
}
|
|
95
|
+
export declare const BOOKING_CONTEXT_SQL = "SELECT b.id, b.status, b.session_id, b.cancel_token, b.locale, b.pass_id, s.starts_at, s.ends_at, s.status AS session_status, s.offering_id,\n\to.kind, o.name AS offering_name, o.cancel_cutoff_min, o.waitlist_lock_min, c.name, c.email\n\tFROM appt_bookings b JOIN appt_sessions s ON s.id = b.session_id JOIN appt_offerings o ON o.id = s.offering_id JOIN appt_customers c ON c.id = b.customer_id";
|
|
96
|
+
export declare const isActive: (status: BookingStatus) => boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Ends a booking and, for a class, promotes the first person in line into the freed seat in the same batch
|
|
99
|
+
* (until the waitlist lock window). A free appointment slot is released. Returns the promoted booking id.
|
|
100
|
+
*/
|
|
101
|
+
export declare function endBooking(env: Bindings, db: D1Database, booking: BookingContext, to: 'cancelled' | 'late_cancelled', now?: number): Promise<string | null>;
|
|
102
|
+
/** Local dates from today for `days` days. */
|
|
103
|
+
export declare function datesAhead(tz: string, days: number, now?: number): string[];
|
|
104
|
+
export interface PassProduct {
|
|
105
|
+
id: string;
|
|
106
|
+
name: string;
|
|
107
|
+
credits: number;
|
|
108
|
+
validity_days: number;
|
|
109
|
+
}
|
|
110
|
+
/** Gives `email` a pass from `product`: staff grants and paid shop orders share this. */
|
|
111
|
+
export declare function passStatements(db: D1Database, product: PassProduct, name: string, email: string): D1PreparedStatement[];
|
|
112
|
+
/** A paid shop order grants a pass for every item whose shop product sells a class pack. */
|
|
113
|
+
export declare function grantPurchasedPasses(env: Bindings, order: ShopOrder): Promise<void>;
|
|
114
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../src/api/appointments/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEpN,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK5C,eAAO,MAAM,GAAG,QAAQ,CAAC;AAEzB,MAAM,WAAW,WAAW;IAC3B,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAChJ,iBAAiB,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,iBAAi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