fix: BookingConfirmPage date format + guest confirmation email on payment

- Fix date display: slice ISO timestamp to first 10 chars before splitting
- Add sendBookingConfirmedEmail() to email.ts — sends green styled HTML email
  with booking details (dates, amount) on payment.succeeded webhook
- Webhook now sends confirmation email to guest email if present

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-08 03:02:18 +03:00
parent fb7d907b40
commit c8d2d87db4
3 changed files with 82 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import { FastifyPluginAsync } from 'fastify'
import { db } from '../db'
import { broadcast } from './ws'
import { sendBookingConfirmedEmail } from '../email'
const yookassaWebhookRoutes: FastifyPluginAsync = async (fastify) => {
// POST /api/yookassa/webhook
@@ -19,8 +20,11 @@ const yookassaWebhookRoutes: FastifyPluginAsync = async (fastify) => {
const { rows } = await db.query<{
id: string; hotel_id: string; booking_id: string | null
total_amount: string; slug: string
guest_name: string; guest_email: string | null
check_in: string; check_out: string; hotel_name: string
}>(
`SELECT ob.id, ob.hotel_id, ob.booking_id, ob.total_amount, h.slug
`SELECT ob.id, ob.hotel_id, ob.booking_id, ob.total_amount, h.slug,
ob.guest_name, ob.guest_email, ob.check_in, ob.check_out, h.name AS hotel_name
FROM online_bookings ob
JOIN hotels h ON h.id = ob.hotel_id
WHERE ob.yookassa_payment_id = $1
@@ -50,6 +54,18 @@ const yookassaWebhookRoutes: FastifyPluginAsync = async (fastify) => {
broadcast(ob.slug, { type: 'booking:updated', booking: bRows[0] })
}
}
// Send confirmation email to guest
if (ob.guest_email) {
sendBookingConfirmedEmail({
to: ob.guest_email,
guestName: ob.guest_name,
hotelName: ob.hotel_name,
checkIn: ob.check_in,
checkOut: ob.check_out,
totalAmount: ob.total_amount,
bookingConfirmUrl: `https://app.hotelsync.ru/booking-confirm/${ob.id}`,
}).catch(() => {}) // don't fail webhook on email error
}
} else if (event === 'payment.canceled') {
await db.query(
`UPDATE online_bookings SET status = 'cancelled', yookassa_status = 'canceled' WHERE id = $1`,