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:
@@ -3,6 +3,7 @@ import { db } from '../db'
|
||||
import { notifyNetupCheckin, notifyNetupCheckout } from './netup'
|
||||
import { getHkSettings } from './housekeeping-settings'
|
||||
import { broadcast } from './ws'
|
||||
import { upsertGuestFromBooking } from '../services/guestUpsert'
|
||||
import { transporter } from '../email'
|
||||
import { createHold } from '../services/yookassa'
|
||||
import { randomUUID } from 'crypto'
|
||||
@@ -108,6 +109,14 @@ const bookings: FastifyPluginAsync = async (fastify) => {
|
||||
)
|
||||
const booking = rows[0]
|
||||
|
||||
// Auto-upsert guest record in CRM
|
||||
upsertGuestFromBooking({
|
||||
hotelId,
|
||||
guestName: guest_name,
|
||||
guestEmail: guest_email,
|
||||
guestPhone: guest_phone,
|
||||
})
|
||||
|
||||
// Auto-create YooKassa hold + send deposit email for online bookings with email
|
||||
if (source === 'online' && guest_email) {
|
||||
try {
|
||||
|
||||
@@ -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