feat: auto-create guest in CRM on booking creation
- Add upsertGuestFromBooking() service — creates or updates guest record when a booking is made (matches by email/phone, creates if not found) - Integrated into bookings.ts (manual PMS bookings) and publicWidget.ts (online widget bookings) - Name parsed as Russian format: "Фамилия Имя [Отчество]" - Non-throwing: booking creation never fails due to guest upsert errors Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { FastifyPluginAsync } from 'fastify'
|
||||
import { db } from '../db'
|
||||
import { getGatewayForModule } from './paymentGateways'
|
||||
import { createCharge } from '../services/yookassa'
|
||||
import { upsertGuestFromBooking } from '../services/guestUpsert'
|
||||
|
||||
type SlugParam = { Params: { slug: string } }
|
||||
type SlugIdParam = { Params: { slug: string; bookingId: string } }
|
||||
@@ -456,6 +457,14 @@ const publicWidget: FastifyPluginAsync = async (fastify) => {
|
||||
await db.query('UPDATE online_bookings SET booking_id = $1 WHERE id = $2',
|
||||
[bookingId, onlineBookingId])
|
||||
|
||||
// Auto-create/update guest in CRM
|
||||
upsertGuestFromBooking({
|
||||
hotelId: hotel.id,
|
||||
guestName,
|
||||
guestEmail,
|
||||
guestPhone,
|
||||
})
|
||||
|
||||
if (paymentMethod === 'yookassa') {
|
||||
// Create YooKassa payment
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user