feat: emit notification events from existing routes

This commit is contained in:
Kirill
2026-05-18 11:39:02 +05:00
parent e73a0ae09a
commit 84cdccaa17
7 changed files with 84 additions and 2 deletions
+18
View File
@@ -1,5 +1,6 @@
import { isDeliveryCarrier } from '../lib/delivery-carrier.js'
import { prisma } from '../lib/prisma.js'
import { NOTIFICATION_EVENTS } from '../../shared/constants/notification-events.js'
export async function registerUserOrderRoutes(fastify) {
// ---- Создание заказа (checkout) ----
@@ -156,6 +157,23 @@ export async function registerUserOrderRoutes(fastify) {
return reply.code(409).send({ error: (e instanceof Error && e.message) || 'Недостаточно товара' })
}
// Emit notification events
request.server.eventBus.emit(NOTIFICATION_EVENTS.ORDER_CREATED, {
orderId: created.id,
userId,
totalCents: created.totalCents,
itemsCount: cartItems.length,
})
// Also emit admin notification
request.server.eventBus.emit('order:created:admin', {
orderId: created.id,
userId,
userEmail: request.user.email || '',
totalCents: created.totalCents,
itemsCount: cartItems.length,
})
return reply.code(201).send({ orderId: created.id })
},
)