@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,254 @@
|
|
|
1
|
+
import { addDays, localParts, zonedToUtc, dayDiff } from '@hintergrund/runtime-contracts';
|
|
2
|
+
import { renderInvoice } from '../../lib/invoice';
|
|
3
|
+
import { ensureSchema } from '../../lib/project-db';
|
|
4
|
+
import { validEmail } from '../../lib/user-recovery';
|
|
5
|
+
import { cancelReservations } from './actions';
|
|
6
|
+
import { DAY, cancelFee, createBooking, isOverbooked, loadConfig, loadCtx, loadSettings, newReference, nightsInsert, text, validDate, vatLines, int } from './core';
|
|
7
|
+
import { randomToken } from '../../lib/features';
|
|
8
|
+
import { sendStayMail } from './mail';
|
|
9
|
+
import { buildDrafts } from './offers';
|
|
10
|
+
import { charge } from './payments';
|
|
11
|
+
const err = (c, status, error, code = 'invalid', warnings) => c.json({ error, code, ...(warnings ? { warnings } : {}) }, status);
|
|
12
|
+
const origin = (c) => new URL(c.req.url).origin;
|
|
13
|
+
const PAID = "(SELECT COALESCE(SUM(CASE kind WHEN 'refund' THEN -amount WHEN 'guarantee' THEN 0 ELSE amount END), 0) FROM stay_payments WHERE booking_id = b.id AND status = 'succeeded')";
|
|
14
|
+
export async function tape(c) {
|
|
15
|
+
const from = c.req.query('from') ?? '', days = Math.min(62, Math.max(1, int(c.req.query('days'), 30)));
|
|
16
|
+
if (!validDate(from))
|
|
17
|
+
return err(c, 400, 'Invalid request.');
|
|
18
|
+
const to = addDays(from, days), db = await ensureSchema(c.env), cfg = await loadConfig(db);
|
|
19
|
+
const [res, blocks, inv] = await Promise.all([
|
|
20
|
+
db.prepare(`SELECT r.*, b.reference, g.name FROM stay_reservations r JOIN stay_bookings b ON b.id = r.booking_id JOIN stay_guests g ON g.id = b.guest_id
|
|
21
|
+
WHERE r.status NOT IN ('cancelled', 'no_show') AND r.arrival < ? AND r.departure > ? ORDER BY r.arrival`).bind(to, from).all(),
|
|
22
|
+
db.prepare('SELECT * FROM stay_blocks WHERE date_from < ? AND date_to > ?').bind(to, from).all(),
|
|
23
|
+
db.prepare('SELECT * FROM stay_inventory WHERE date >= ? AND date < ?').bind(from, to).all(),
|
|
24
|
+
]);
|
|
25
|
+
return c.json({
|
|
26
|
+
from, to, units: cfg.units, roomTypes: cfg.roomTypes,
|
|
27
|
+
reservations: res.results.map(r => ({ id: r.id, bookingId: r.booking_id, reference: r.reference, unitId: r.unit_id, roomTypeId: r.room_type_id, arrival: r.arrival, departure: r.departure, status: r.status, guestName: r.name, adults: r.adults, children: JSON.parse(r.children_ages_json).length })),
|
|
28
|
+
blocks: blocks.results.map(b => ({ id: b.id, unitId: b.unit_id, dateFrom: b.date_from, dateTo: b.date_to, reason: b.reason, source: b.source })),
|
|
29
|
+
inventory: inv.results.map(i => ({ roomTypeId: i.room_type_id, date: i.date, capacity: i.capacity, sold: i.sold })),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const summary = (r) => ({
|
|
33
|
+
id: r.id, reference: r.reference, status: r.status, guestName: r.gname, guestEmail: r.gemail, arrival: r.arrival, departure: r.departure, rooms: r.rooms, total: r.total, paid: r.paid, createdAt: r.created_at, source: r.source,
|
|
34
|
+
});
|
|
35
|
+
/** Filters: q (reference, name, email), status, arrival / departure / inhouse (a date), limit, offset. */
|
|
36
|
+
export async function listBookings(c) {
|
|
37
|
+
const q = c.req.query(), where = ['1 = 1'], args = [];
|
|
38
|
+
if (q.q) {
|
|
39
|
+
where.push('(b.reference LIKE ? OR g.name LIKE ? OR g.email LIKE ?)');
|
|
40
|
+
const like = `%${text(q.q, 100)}%`;
|
|
41
|
+
args.push(like, like, like);
|
|
42
|
+
}
|
|
43
|
+
if (q.status === 'confirmed' || q.status === 'cancelled') {
|
|
44
|
+
where.push('b.status = ?');
|
|
45
|
+
args.push(q.status);
|
|
46
|
+
}
|
|
47
|
+
const live = "status NOT IN ('cancelled', 'no_show')";
|
|
48
|
+
if (validDate(q.arrival)) {
|
|
49
|
+
where.push(`b.id IN (SELECT booking_id FROM stay_reservations WHERE arrival = ? AND ${live})`);
|
|
50
|
+
args.push(q.arrival);
|
|
51
|
+
}
|
|
52
|
+
if (validDate(q.departure)) {
|
|
53
|
+
where.push(`b.id IN (SELECT booking_id FROM stay_reservations WHERE departure = ? AND ${live})`);
|
|
54
|
+
args.push(q.departure);
|
|
55
|
+
}
|
|
56
|
+
if (validDate(q.inhouse)) {
|
|
57
|
+
where.push(`b.id IN (SELECT booking_id FROM stay_reservations WHERE arrival <= ?1 AND departure > ?1 AND ${live})`.replaceAll('?1', '?'));
|
|
58
|
+
args.push(q.inhouse, q.inhouse);
|
|
59
|
+
}
|
|
60
|
+
const db = await ensureSchema(c.env), limit = Math.min(200, Math.max(1, int(q.limit, 50))), offset = Math.max(0, int(q.offset));
|
|
61
|
+
const from = 'FROM stay_bookings b JOIN stay_guests g ON g.id = b.guest_id JOIN stay_reservations r ON r.booking_id = b.id';
|
|
62
|
+
const [rows, count] = await Promise.all([
|
|
63
|
+
db.prepare(`SELECT b.*, g.name AS gname, g.email AS gemail, MIN(r.arrival) AS arrival, MAX(r.departure) AS departure, COUNT(r.id) AS rooms, ${PAID} AS paid ${from} WHERE ${where.join(' AND ')} GROUP BY b.id ORDER BY ${q.arrival ? 'arrival' : 'b.created_at DESC'} LIMIT ? OFFSET ?`).bind(...args, limit, offset).all(),
|
|
64
|
+
db.prepare(`SELECT COUNT(DISTINCT b.id) AS n ${from} WHERE ${where.join(' AND ')}`).bind(...args).first(),
|
|
65
|
+
]);
|
|
66
|
+
return c.json({ bookings: rows.results.map(summary), total: count?.n ?? 0 });
|
|
67
|
+
}
|
|
68
|
+
async function detail(db, id) {
|
|
69
|
+
const b = await db.prepare(`SELECT b.*, g.name AS gname, g.email AS gemail, ${PAID} AS paid FROM stay_bookings b JOIN stay_guests g ON g.id = b.guest_id WHERE b.id = ?`).bind(id).first();
|
|
70
|
+
if (!b)
|
|
71
|
+
return null;
|
|
72
|
+
const s = await loadSettings(db);
|
|
73
|
+
const [guest, res, extras, pays, invoices, types] = await Promise.all([
|
|
74
|
+
db.prepare('SELECT * FROM stay_guests WHERE id = ?').bind(b.guest_id).first(), db.prepare('SELECT * FROM stay_reservations WHERE booking_id = ? ORDER BY arrival, id').bind(id).all(),
|
|
75
|
+
db.prepare('SELECT e.* FROM stay_reservation_extras e JOIN stay_reservations r ON r.id = e.reservation_id WHERE r.booking_id = ?').bind(id).all(),
|
|
76
|
+
db.prepare('SELECT * FROM stay_payments WHERE booking_id = ? ORDER BY created_at').bind(id).all(), db.prepare('SELECT id, number, issued_at, total FROM stay_invoices WHERE booking_id = ? ORDER BY seq').bind(id).all(),
|
|
77
|
+
db.prepare('SELECT id, name FROM stay_room_types').all(),
|
|
78
|
+
]);
|
|
79
|
+
const g = guest, names = new Map(types.results.map(t => [t.id, t.name]));
|
|
80
|
+
const reservations = res.results.map(r => ({
|
|
81
|
+
id: r.id, bookingId: id, roomTypeId: r.room_type_id, ratePlanId: r.rate_plan_id, unitId: r.unit_id, roomTypeName: names.get(r.room_type_id) ?? '', ratePlanName: r.plan_name, board: r.board, arrival: r.arrival, departure: r.departure,
|
|
82
|
+
adults: r.adults, childrenAges: JSON.parse(r.children_ages_json), status: r.status, nightly: JSON.parse(r.nightly_json), extras: extras.results.filter(e => e.reservation_id === r.id).map(e => ({ name: e.name, quantity: e.quantity, total: e.total })),
|
|
83
|
+
total: r.total, cityTax: r.city_tax, fee: r.fee, dueNow: r.due_now, vat: JSON.parse(r.vat_json),
|
|
84
|
+
policy: JSON.parse(r.policy_json), cancelFee: cancelFee(s, JSON.parse(r.policy_json), { arrival: r.arrival, nightly: JSON.parse(r.nightly_json), total: r.total }, Date.now()),
|
|
85
|
+
}));
|
|
86
|
+
return {
|
|
87
|
+
...summary({ ...b, arrival: reservations[0]?.arrival ?? '', departure: reservations.reduce((m, r) => r.departure > m ? r.departure : m, ''), rooms: reservations.length }),
|
|
88
|
+
guest: { id: g.id, name: g.name, email: g.email, phone: g.phone, country: g.country, nationality: g.nationality, birthdate: g.birthdate, idDoc: g.id_doc, purgeAfter: g.purge_after },
|
|
89
|
+
meldescheinRequired: !!g.country && g.country.toUpperCase() !== s.country.toUpperCase(), reservations,
|
|
90
|
+
payments: pays.results.map(p => ({ id: p.id, kind: p.kind, status: p.status, amount: p.amount, stripeId: p.stripe_id, note: p.note, createdAt: p.created_at })),
|
|
91
|
+
invoices: invoices.results.map(i => ({ id: i.id, number: i.number, issuedAt: i.issued_at, total: i.total })),
|
|
92
|
+
currency: b.currency, cityTax: b.city_tax, guarantee: b.guarantee, hasCard: !!b.stripe_payment_method_id, note: b.note, locale: b.locale, manageToken: b.manage_token,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export async function getBooking(c) {
|
|
96
|
+
const found = await detail(await ensureSchema(c.env), c.req.param('id') ?? '');
|
|
97
|
+
return found ? c.json(found) : c.notFound();
|
|
98
|
+
}
|
|
99
|
+
/** Staff booking: restrictions can be overridden with `force` (they come back as warnings first); a full night never can. Nothing is charged online. */
|
|
100
|
+
export async function manualBooking(c) {
|
|
101
|
+
const body = await c.req.json().catch(() => null);
|
|
102
|
+
const name = text(body?.guest?.name, 120), email = text(body?.guest?.email, 254).toLowerCase();
|
|
103
|
+
if (!body || !name || (email && !validEmail(email)) || !validDate(body.arrival) || !validDate(body.departure) || !Array.isArray(body.rooms) || !body.rooms.length || body.rooms.length > 20)
|
|
104
|
+
return err(c, 400, 'Invalid request.');
|
|
105
|
+
const nights = dayDiff(body.arrival, body.departure);
|
|
106
|
+
if (nights < 1 || nights > 90)
|
|
107
|
+
return err(c, 400, 'Invalid dates.');
|
|
108
|
+
const db = await ensureSchema(c.env), ctx = await loadCtx(db, body.arrival, body.departure);
|
|
109
|
+
const built = buildDrafts(ctx, body.arrival, body.departure, body.rooms, '', true, body.force === true);
|
|
110
|
+
if (!('drafts' in built))
|
|
111
|
+
return err(c, 409, built.error, built.code === 'restricted' ? 'restricted' : 'unavailable', built.warnings);
|
|
112
|
+
const drafts = built.drafts.map(d => ({ ...d, dueNow: 0 }));
|
|
113
|
+
const id = crypto.randomUUID(), reference = newReference();
|
|
114
|
+
try {
|
|
115
|
+
await createBooking(db, { id, guestId: crypto.randomUUID(), reference, manageToken: randomToken(), source: 'staff', currency: ctx.s.currency, guest: { name, email, phone: text(body.guest?.phone, 40), country: text(body.guest?.country, 2).toUpperCase() }, drafts, note: text(body.note, 500), locale: body.locale === 'de' ? 'de' : 'en', guarantee: 'none' });
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
return isOverbooked(error) ? err(c, 409, 'Not enough rooms left.', 'unavailable') : Promise.reject(error);
|
|
119
|
+
}
|
|
120
|
+
if (email && body.sendEmail !== false)
|
|
121
|
+
await sendStayMail(c.env, db, origin(c), id, 'confirmation');
|
|
122
|
+
return c.json({ id, reference, warnings: built.warnings ?? [] }, 201);
|
|
123
|
+
}
|
|
124
|
+
export async function moveUnit(c) {
|
|
125
|
+
const body = await c.req.json().catch(() => null), id = c.req.param('id') ?? '';
|
|
126
|
+
if (!body || !('unitId' in body))
|
|
127
|
+
return err(c, 400, 'Invalid request.');
|
|
128
|
+
const db = await ensureSchema(c.env);
|
|
129
|
+
const r = await db.prepare("SELECT * FROM stay_reservations WHERE id = ? AND status IN ('booked', 'checked_in')").bind(id).first();
|
|
130
|
+
if (!r)
|
|
131
|
+
return err(c, 404, 'Reservation not found.', 'not_found');
|
|
132
|
+
const unit = body.unitId ? await db.prepare('SELECT * FROM stay_units WHERE id = ? AND active = 1').bind(body.unitId).first() : null;
|
|
133
|
+
if (body.unitId && !unit)
|
|
134
|
+
return err(c, 404, 'Unit not found.', 'not_found');
|
|
135
|
+
const retype = unit && unit.room_type_id !== r.room_type_id;
|
|
136
|
+
try {
|
|
137
|
+
await db.batch([
|
|
138
|
+
db.prepare('DELETE FROM stay_unit_nights WHERE reservation_id = ?').bind(id),
|
|
139
|
+
...(retype ? [db.prepare('UPDATE stay_inventory SET sold = sold - 1 WHERE room_type_id = ? AND date >= ? AND date < ?').bind(r.room_type_id, r.arrival, r.departure),
|
|
140
|
+
db.prepare('UPDATE stay_inventory SET sold = sold + 1 WHERE room_type_id = ? AND date >= ? AND date < ?').bind(unit.room_type_id, r.arrival, r.departure)] : []),
|
|
141
|
+
...(unit ? [nightsInsert(db, unit.id, r.arrival, r.departure, { reservationId: id })] : []),
|
|
142
|
+
db.prepare('UPDATE stay_reservations SET unit_id = ?, room_type_id = ? WHERE id = ?').bind(unit?.id ?? null, unit?.room_type_id ?? r.room_type_id, id),
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
return err(c, 409, isOverbooked(error) ? 'No room of that type is left on those nights.' : 'The unit is occupied on those nights.', 'conflict');
|
|
147
|
+
}
|
|
148
|
+
return c.json({ ok: true });
|
|
149
|
+
}
|
|
150
|
+
export async function reservationAction(c) {
|
|
151
|
+
const body = await c.req.json().catch(() => null), id = c.req.param('id') ?? '';
|
|
152
|
+
const db = await ensureSchema(c.env), r = await db.prepare('SELECT * FROM stay_reservations WHERE id = ?').bind(id).first();
|
|
153
|
+
if (!body || !r)
|
|
154
|
+
return err(c, r ? 400 : 404, r ? 'Invalid request.' : 'Reservation not found.', r ? 'invalid' : 'not_found');
|
|
155
|
+
if (body.action === 'check_in' || body.action === 'check_out') {
|
|
156
|
+
const [from, to] = body.action === 'check_in' ? ['booked', 'checked_in'] : ['checked_in', 'checked_out'];
|
|
157
|
+
const done = await db.prepare('UPDATE stay_reservations SET status = ? WHERE id = ? AND status = ?').bind(to, id, from).run();
|
|
158
|
+
return done.meta.changes ? c.json({ status: to, fee: 0, refunded: 0, charged: 0 }) : err(c, 409, `Reservation is not ${from}.`, 'conflict');
|
|
159
|
+
}
|
|
160
|
+
if (body.action !== 'cancel' && body.action !== 'no_show')
|
|
161
|
+
return err(c, 400, 'Invalid request.');
|
|
162
|
+
if (r.status !== 'booked')
|
|
163
|
+
return err(c, 409, 'Reservation is not booked.', 'conflict');
|
|
164
|
+
const booking = (await db.prepare('SELECT * FROM stay_bookings WHERE id = ?').bind(r.booking_id).first());
|
|
165
|
+
return c.json(await cancelReservations(c.env, db, origin(c), booking, [r], { noShow: body.action === 'no_show', feeOverride: body.feeOverride == null ? undefined : Math.max(0, int(body.feeOverride)) }));
|
|
166
|
+
}
|
|
167
|
+
/** Cancels every still-booked room of a booking. */
|
|
168
|
+
export async function cancelBooking(c) {
|
|
169
|
+
const body = await c.req.json().catch(() => ({}));
|
|
170
|
+
const db = await ensureSchema(c.env), booking = await db.prepare('SELECT * FROM stay_bookings WHERE id = ?').bind(c.req.param('id') ?? '').first();
|
|
171
|
+
if (!booking)
|
|
172
|
+
return c.notFound();
|
|
173
|
+
const rows = (await db.prepare("SELECT * FROM stay_reservations WHERE booking_id = ? AND status = 'booked'").bind(booking.id).all()).results;
|
|
174
|
+
if (!rows.length)
|
|
175
|
+
return err(c, 409, 'Nothing to cancel.', 'conflict');
|
|
176
|
+
return c.json(await cancelReservations(c.env, db, origin(c), booking, rows, { feeOverride: body.feeOverride == null ? undefined : Math.max(0, int(body.feeOverride)) }));
|
|
177
|
+
}
|
|
178
|
+
export async function chargeFee(c) {
|
|
179
|
+
const body = await c.req.json().catch(() => null), amount = int(body?.amount);
|
|
180
|
+
const db = await ensureSchema(c.env), booking = await db.prepare('SELECT * FROM stay_bookings WHERE id = ?').bind(c.req.param('id') ?? '').first();
|
|
181
|
+
if (!booking)
|
|
182
|
+
return c.notFound();
|
|
183
|
+
if (amount < 1 || amount > 10_000_000)
|
|
184
|
+
return err(c, 400, 'Invalid amount.');
|
|
185
|
+
try {
|
|
186
|
+
return c.json(await charge(c.env, db, origin(c), booking, amount, text(body?.reason, 100) || 'fee'));
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
return c.json({ error: error.message, code: 'payment_failed' }, 400);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export async function updateGuest(c) {
|
|
193
|
+
const body = await c.req.json().catch(() => null), id = c.req.param('id') ?? '';
|
|
194
|
+
const db = await ensureSchema(c.env), g = await db.prepare('SELECT * FROM stay_guests WHERE id = ?').bind(id).first();
|
|
195
|
+
if (!body || !g)
|
|
196
|
+
return c.notFound();
|
|
197
|
+
const s = await loadSettings(db), last = (await db.prepare('SELECT MAX(r.departure) AS d FROM stay_reservations r JOIN stay_bookings b ON b.id = r.booking_id WHERE b.guest_id = ?').bind(id).first())?.d;
|
|
198
|
+
const birthdate = 'birthdate' in body ? (validDate(body.birthdate) ? body.birthdate : null) : g.birthdate, idDoc = 'idDoc' in body ? (text(body.idDoc, 200) || null) : g.id_doc;
|
|
199
|
+
// ID data is kept for `idRetentionDays` after the last departure, then purged by cron.
|
|
200
|
+
const purgeAfter = birthdate || idDoc ? zonedToUtc(last ?? localParts(Date.now(), s.timezone).date, 0, s.timezone) + s.idRetentionDays * DAY : null;
|
|
201
|
+
await db.prepare('UPDATE stay_guests SET name = ?, email = ?, phone = ?, country = ?, nationality = ?, birthdate = ?, id_doc = ?, purge_after = ? WHERE id = ?')
|
|
202
|
+
.bind(text(body.name ?? g.name, 120), text(body.email ?? g.email, 254).toLowerCase(), text(body.phone ?? g.phone, 40), text(body.country ?? g.country, 2).toUpperCase(), text(body.nationality ?? g.nationality, 2).toUpperCase(), birthdate, idDoc, purgeAfter, id).run();
|
|
203
|
+
return c.json({ ok: true });
|
|
204
|
+
}
|
|
205
|
+
// --- Invoices ---
|
|
206
|
+
const money = (cents) => cents / 100;
|
|
207
|
+
/** One invoice per booking: re-issuing returns the existing one. Lines are gross; VAT is itemised in the notes. */
|
|
208
|
+
export async function issueInvoice(c) {
|
|
209
|
+
const db = await ensureSchema(c.env), id = c.req.param('id') ?? '';
|
|
210
|
+
const existing = await db.prepare('SELECT id, number, issued_at, total FROM stay_invoices WHERE booking_id = ? ORDER BY seq DESC LIMIT 1').bind(id).first();
|
|
211
|
+
if (existing)
|
|
212
|
+
return c.json({ id: existing.id, number: existing.number, issuedAt: existing.issued_at, total: existing.total });
|
|
213
|
+
const b = await detail(db, id), s = await loadSettings(db);
|
|
214
|
+
if (!b)
|
|
215
|
+
return c.notFound();
|
|
216
|
+
const extras = (await db.prepare('SELECT e.* FROM stay_reservation_extras e JOIN stay_reservations r ON r.id = e.reservation_id WHERE r.booking_id = ?').bind(id).all()).results;
|
|
217
|
+
const live = b.reservations.filter(r => r.status !== 'cancelled' && r.status !== 'no_show'), fees = b.reservations.filter(r => r.fee > 0 && (r.status === 'cancelled' || r.status === 'no_show'));
|
|
218
|
+
const items = [
|
|
219
|
+
...live.flatMap(r => {
|
|
220
|
+
const rows = extras.filter(e => e.reservation_id === r.id), room = r.total - rows.reduce((sum, e) => sum + e.total, 0);
|
|
221
|
+
return [{ description: `${r.roomTypeName}, ${r.ratePlanName}: ${r.arrival} - ${r.departure} (${r.nightly.length} nights)`, quantity: 1, unitPrice: money(room), total: money(room) },
|
|
222
|
+
...rows.map(e => ({ description: e.name, quantity: e.quantity, unitPrice: money(e.total / e.quantity), total: money(e.total) }))];
|
|
223
|
+
}),
|
|
224
|
+
...fees.map(r => ({ description: `Cancellation fee ${r.arrival} - ${r.departure}`, quantity: 1, unitPrice: money(r.fee), total: money(r.fee) })),
|
|
225
|
+
...(b.cityTax && live.length ? [{ description: 'Tourist tax (not subject to VAT)', quantity: 1, unitPrice: money(live.reduce((sum, r) => sum + r.cityTax, 0)), total: money(live.reduce((sum, r) => sum + r.cityTax, 0)) }] : []),
|
|
226
|
+
];
|
|
227
|
+
const vat = vatLines(live.flatMap(r => r.vat.map(v => ({ rate: v.rate, gross: v.gross }))));
|
|
228
|
+
const tax = vat.reduce((sum, v) => sum + v.vat, 0), total = Math.round(items.reduce((sum, i) => sum + i.total, 0) * 100);
|
|
229
|
+
const now = Date.now(), invoiceId = crypto.randomUUID();
|
|
230
|
+
const data = {
|
|
231
|
+
invoiceNumber: '', invoiceDate: localParts(now, s.timezone).date, customerName: b.guest.name, customerEmail: b.guest.email, customerAddress: b.guest.country || undefined,
|
|
232
|
+
items, subtotal: money(total - Math.round(tax * 1)), tax: money(tax), total: money(total), currency: b.currency.toUpperCase(),
|
|
233
|
+
notes: [...vat.map(v => `VAT ${v.rate}%: ${(v.gross / 100).toFixed(2)} gross, ${(v.vat / 100).toFixed(2)} VAT`), `Booking ${b.reference}`].join('\n'),
|
|
234
|
+
};
|
|
235
|
+
// The number is taken inside the insert, so concurrent invoices cannot share one.
|
|
236
|
+
const insert = () => db.prepare(`INSERT INTO stay_invoices (id, booking_id, seq, number, issued_at, total, lines_json)
|
|
237
|
+
SELECT ?1, ?2, n, ?3 || printf('%05d', n), ?4, ?5, '' FROM (SELECT COALESCE(MAX(seq), 0) + 1 AS n FROM stay_invoices)`).bind(invoiceId, id, s.invoicePrefix, now, total).run();
|
|
238
|
+
try {
|
|
239
|
+
await insert();
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
await insert();
|
|
243
|
+
}
|
|
244
|
+
const row = (await db.prepare('SELECT number FROM stay_invoices WHERE id = ?').bind(invoiceId).first());
|
|
245
|
+
data.invoiceNumber = row.number;
|
|
246
|
+
await db.prepare('UPDATE stay_invoices SET lines_json = ? WHERE id = ?').bind(JSON.stringify(data), invoiceId).run();
|
|
247
|
+
return c.json({ id: invoiceId, number: row.number, issuedAt: now, total }, 201);
|
|
248
|
+
}
|
|
249
|
+
export async function invoicePdf(c) {
|
|
250
|
+
const row = await (await ensureSchema(c.env)).prepare('SELECT number, lines_json FROM stay_invoices WHERE id = ?').bind(c.req.param('id') ?? '').first();
|
|
251
|
+
if (!row?.lines_json)
|
|
252
|
+
return c.notFound();
|
|
253
|
+
return new Response(await renderInvoice(c.env, JSON.parse(row.lines_json)), { headers: { 'Content-Type': 'application/pdf', 'Content-Disposition': `inline; filename="${row.number}.pdf"` } });
|
|
254
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { type StayBoard, type StayBookingView, type StayCancelPolicy, type StayCancelTier, type StayCancellationSummary, type StayConfig, type StayEntity, type StayGuarantee, type StayHoldRoom, type StayRoomRequest, type StaySettings, type StaySearchRequest, type StayVatLine } from '@hintergrund/runtime-contracts';
|
|
2
|
+
export type Row = Record<string, any>;
|
|
3
|
+
export declare const HOUR = 3600000;
|
|
4
|
+
export declare const DAY = 86400000;
|
|
5
|
+
export declare const MAX_HORIZON_DAYS = 730;
|
|
6
|
+
export declare function newReference(): string;
|
|
7
|
+
export declare const validDate: (value: unknown) => value is string;
|
|
8
|
+
export declare const text: (value: unknown, max: number) => string;
|
|
9
|
+
export declare const int: (value: unknown, fallback?: number) => number;
|
|
10
|
+
export declare const marks: (n: number) => string;
|
|
11
|
+
export declare const minutesOf: (hhmm: string) => number;
|
|
12
|
+
type Kind = 's' | 'i' | 'b' | 'j' | 'ns' | 'ni' | 'r';
|
|
13
|
+
export declare const ENTITY_DEFS: Record<StayEntity, {
|
|
14
|
+
table: string;
|
|
15
|
+
order: string;
|
|
16
|
+
cols: Record<string, [string, Kind]>;
|
|
17
|
+
}>;
|
|
18
|
+
/** Writable `[column, value]` pairs of the keys the body carries. */
|
|
19
|
+
export declare function entityFields(entity: StayEntity, body: Record<string, any>): [string, unknown][];
|
|
20
|
+
export declare function loadSettings(db: D1Database): Promise<StaySettings>;
|
|
21
|
+
export declare function loadConfig(db: D1Database): Promise<StayConfig>;
|
|
22
|
+
/** Recomputes capacity of a room type from `from` on; the CHECK throws when more is sold than the new capacity (409 for the caller). */
|
|
23
|
+
export declare const syncCapacity: (db: D1Database, roomTypeId: string, from: string) => D1PreparedStatement;
|
|
24
|
+
/** Creates the inventory rows up to 24 months ahead for every room type; existing rows are left alone. */
|
|
25
|
+
export declare function seedInventory(db: D1Database, today: string): Promise<void>;
|
|
26
|
+
/** Statement inserting one unit_night per night of [from, to) for a reservation or block. */
|
|
27
|
+
export declare const nightsInsert: (db: D1Database, unitId: string, from: string, to: string, ref: {
|
|
28
|
+
reservationId?: string;
|
|
29
|
+
blockId?: string;
|
|
30
|
+
}, ignore?: boolean) => D1PreparedStatement;
|
|
31
|
+
/** Puts a reservation on a free unit of its room type when one exists; a lost race leaves it unassigned. */
|
|
32
|
+
export declare function autoAssign(db: D1Database, reservationId: string): Promise<void>;
|
|
33
|
+
export interface Ctx {
|
|
34
|
+
s: StaySettings;
|
|
35
|
+
now: number;
|
|
36
|
+
today: string;
|
|
37
|
+
types: Map<string, Row>;
|
|
38
|
+
plans: Map<string, Row>;
|
|
39
|
+
planRooms: Map<string, Row>;
|
|
40
|
+
days: Map<string, Row>;
|
|
41
|
+
inv: Map<string, Row>;
|
|
42
|
+
yields: Row[];
|
|
43
|
+
policies: Map<string, Row>;
|
|
44
|
+
tax: Row[];
|
|
45
|
+
extras: Map<string, Row>;
|
|
46
|
+
}
|
|
47
|
+
/** Everything the offer engine needs for stays touching [from, to] (both inclusive: the departure day carries the CTD flag). */
|
|
48
|
+
export declare function loadCtx(db: D1Database, from: string, to: string, now?: number): Promise<Ctx>;
|
|
49
|
+
/** Rooms of a type free on every night; holds are inside `sold`. */
|
|
50
|
+
export declare function available(ctx: Ctx, roomTypeId: string, arrival: string, departure: string): number;
|
|
51
|
+
/** Yield: the biggest uplift of a rule whose occupancy threshold the night has reached. */
|
|
52
|
+
export declare function yieldUplift(ctx: Ctx, roomTypeId: string, date: string): number;
|
|
53
|
+
/** Room price of a night (derived plans and yield applied, no occupancy supplements); null when not sellable. */
|
|
54
|
+
export declare function nightPrice(ctx: Ctx, roomTypeId: string, plan: Row, date: string): number | null;
|
|
55
|
+
/** Children from `childMaxAge` count as adults. */
|
|
56
|
+
export declare function splitGuests(s: StaySettings, room: StayRoomRequest): {
|
|
57
|
+
adults: number;
|
|
58
|
+
kids: number[];
|
|
59
|
+
};
|
|
60
|
+
export declare const vatLines: (parts: {
|
|
61
|
+
rate: number;
|
|
62
|
+
gross: number;
|
|
63
|
+
}[]) => StayVatLine[];
|
|
64
|
+
export declare function cityTax(ctx: Ctx, arrival: string, departure: string, adults: number, kids: number[]): number;
|
|
65
|
+
export interface Quote {
|
|
66
|
+
roomTypeId: string;
|
|
67
|
+
ratePlanId: string;
|
|
68
|
+
planName: string;
|
|
69
|
+
board: StayBoard;
|
|
70
|
+
nightly: {
|
|
71
|
+
date: string;
|
|
72
|
+
price: number;
|
|
73
|
+
}[];
|
|
74
|
+
roomTotal: number;
|
|
75
|
+
vat: StayVatLine[];
|
|
76
|
+
cityTax: number;
|
|
77
|
+
adults: number;
|
|
78
|
+
kids: number[];
|
|
79
|
+
policy: PolicySnapshot;
|
|
80
|
+
/** Why the stay cannot be sold online; `hard` ones even staff cannot override. */
|
|
81
|
+
problems: string[];
|
|
82
|
+
hard: boolean;
|
|
83
|
+
}
|
|
84
|
+
export interface PolicySnapshot {
|
|
85
|
+
id: string | null;
|
|
86
|
+
name: string;
|
|
87
|
+
tiers: StayCancelTier[];
|
|
88
|
+
noShow: StayCancelPolicy['noShow'];
|
|
89
|
+
guarantee: StayGuarantee;
|
|
90
|
+
depositPct: number;
|
|
91
|
+
}
|
|
92
|
+
export declare function policyOf(ctx: Ctx, plan: Row): PolicySnapshot;
|
|
93
|
+
/** Prices one room of a stay on one plan and lists every rule it breaks. */
|
|
94
|
+
export declare function quote(ctx: Ctx, roomType: Row, plan: Row, room: StayRoomRequest, arrival: string, departure: string): Quote;
|
|
95
|
+
/** Instant the stay begins: arrival date at the check-in time. */
|
|
96
|
+
export declare const arrivalAt: (s: StaySettings, arrival: string) => number;
|
|
97
|
+
/** Fee of a cancellation (or no-show) made at `now`, from the policy snapshot and nightly prices. */
|
|
98
|
+
export declare function cancelFee(s: StaySettings, policy: PolicySnapshot, r: {
|
|
99
|
+
arrival: string;
|
|
100
|
+
nightly: {
|
|
101
|
+
price: number;
|
|
102
|
+
}[];
|
|
103
|
+
total: number;
|
|
104
|
+
}, now: number, noShow?: boolean): number;
|
|
105
|
+
export declare function dueNow(policy: PolicySnapshot, total: number): number;
|
|
106
|
+
export declare function summary(s: StaySettings, policy: PolicySnapshot, arrival: string, total: number, now: number): StayCancellationSummary;
|
|
107
|
+
export declare function parseSearch(body: Partial<StaySearchRequest> | null, s: StaySettings, today: string): {
|
|
108
|
+
arrival: string;
|
|
109
|
+
departure: string;
|
|
110
|
+
rooms: StayRoomRequest[];
|
|
111
|
+
promo: string;
|
|
112
|
+
} | string;
|
|
113
|
+
/** Private plans need their code; staff (no promo given) can use any. */
|
|
114
|
+
export declare const planEligible: (plan: Row, promo: string) => boolean;
|
|
115
|
+
export declare function priceExtras(ctx: Ctx, picks: {
|
|
116
|
+
extraId: string;
|
|
117
|
+
quantity?: number;
|
|
118
|
+
}[] | undefined, persons: number, nights: number): {
|
|
119
|
+
extraId: string;
|
|
120
|
+
name: string;
|
|
121
|
+
quantity: number;
|
|
122
|
+
total: number;
|
|
123
|
+
vatRate: number;
|
|
124
|
+
}[];
|
|
125
|
+
export interface Draft {
|
|
126
|
+
roomTypeId: string;
|
|
127
|
+
ratePlanId: string;
|
|
128
|
+
planName: string;
|
|
129
|
+
board: string;
|
|
130
|
+
adults: number;
|
|
131
|
+
kids: number[];
|
|
132
|
+
arrival: string;
|
|
133
|
+
departure: string;
|
|
134
|
+
nightly: {
|
|
135
|
+
date: string;
|
|
136
|
+
price: number;
|
|
137
|
+
}[];
|
|
138
|
+
roomTotal: number;
|
|
139
|
+
total: number;
|
|
140
|
+
cityTax: number;
|
|
141
|
+
vat: StayVatLine[];
|
|
142
|
+
dueNow: number;
|
|
143
|
+
policy: PolicySnapshot;
|
|
144
|
+
extras: {
|
|
145
|
+
extraId: string;
|
|
146
|
+
name: string;
|
|
147
|
+
quantity: number;
|
|
148
|
+
total: number;
|
|
149
|
+
vatRate: number;
|
|
150
|
+
}[];
|
|
151
|
+
unitId?: string;
|
|
152
|
+
}
|
|
153
|
+
export declare function toDraft(ctx: Ctx, q: Quote, arrival: string, departure: string, room: Pick<StayHoldRoom, 'extras'>, totalOverride?: number): Draft;
|
|
154
|
+
/** Statements adding `qty` sold per night; the CHECK aborts the batch when a night is full. `guard` limits them to a still-valid hold. */
|
|
155
|
+
export declare function acquireStmts(db: D1Database, items: {
|
|
156
|
+
roomTypeId: string;
|
|
157
|
+
arrival: string;
|
|
158
|
+
departure: string;
|
|
159
|
+
qty: number;
|
|
160
|
+
}[], guard?: {
|
|
161
|
+
holdId: string;
|
|
162
|
+
expiresAt: number;
|
|
163
|
+
}): D1PreparedStatement[];
|
|
164
|
+
export declare function aggregateItems(drafts: Draft[]): {
|
|
165
|
+
roomTypeId: string;
|
|
166
|
+
arrival: string;
|
|
167
|
+
departure: string;
|
|
168
|
+
qty: number;
|
|
169
|
+
}[];
|
|
170
|
+
/** Returns an expired hold's nights to the inventory, atomically with marking it expired. */
|
|
171
|
+
export declare function releaseHold(db: D1Database, holdId: string): Promise<void>;
|
|
172
|
+
export declare function releaseExpiredHolds(db: D1Database, now?: number): Promise<void>;
|
|
173
|
+
export interface Pay {
|
|
174
|
+
kind: 'guarantee' | 'deposit';
|
|
175
|
+
stripeId: string;
|
|
176
|
+
amount: number;
|
|
177
|
+
}
|
|
178
|
+
export interface NewBooking {
|
|
179
|
+
id: string;
|
|
180
|
+
guestId: string;
|
|
181
|
+
reference: string;
|
|
182
|
+
manageToken: string;
|
|
183
|
+
source: 'online' | 'staff';
|
|
184
|
+
currency: string;
|
|
185
|
+
guest: {
|
|
186
|
+
name: string;
|
|
187
|
+
email: string;
|
|
188
|
+
phone?: string;
|
|
189
|
+
country?: string;
|
|
190
|
+
};
|
|
191
|
+
drafts: Draft[];
|
|
192
|
+
promo?: string;
|
|
193
|
+
note?: string;
|
|
194
|
+
locale: string;
|
|
195
|
+
stripe?: {
|
|
196
|
+
customerId?: string;
|
|
197
|
+
paymentMethodId?: string;
|
|
198
|
+
paymentIntentId?: string;
|
|
199
|
+
sessionId?: string;
|
|
200
|
+
};
|
|
201
|
+
pays?: Pay[];
|
|
202
|
+
guarantee: StayGuarantee;
|
|
203
|
+
}
|
|
204
|
+
/** Statements creating the booking, guest, reservations, extras and payments. With `holdId` they take effect only if this call converts the active hold (the previous statement is the claim). */
|
|
205
|
+
export declare function bookingStmts(db: D1Database, b: NewBooking, holdId?: string): {
|
|
206
|
+
reservationIds: string[];
|
|
207
|
+
stmts: D1PreparedStatement[];
|
|
208
|
+
};
|
|
209
|
+
/** Creates a booking in one batch (inventory taken with it, CHECK aborts on oversell), then assigns units. Throws when a night is full. */
|
|
210
|
+
export declare function createBooking(db: D1Database, b: NewBooking): Promise<void>;
|
|
211
|
+
export declare const isOverbooked: (error: unknown) => boolean;
|
|
212
|
+
export declare function bookingView(db: D1Database, s: StaySettings, booking: Row, now?: number): Promise<StayBookingView>;
|
|
213
|
+
export {};
|
|
214
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../src/api/stays/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,KAAK,uBAAuB,EAAsB,KAAK,UAAU,EAAE,KAAK,UAAU,EACpK,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,WAAW,EACxH,MAAM,gCAAgC,CAAC;AAIxC,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACtC,eAAO,MAAM,IAAI,UAAU,CAAC;AAC5B,eAAO,MAAM,GAAG,WAAW,CAAC;AAC5B,eAAO,MAAM,gBAAgB,MAAM,CAA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