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
+9
View File
@@ -1,4 +1,5 @@
import { prisma } from '../lib/prisma.js'
import { NOTIFICATION_EVENTS } from '../../shared/constants/notification-events.js'
export async function registerUserMessageRoutes(fastify) {
fastify.get(
@@ -26,6 +27,14 @@ export async function registerUserMessageRoutes(fastify) {
if (!text) return reply.code(400).send({ error: 'Сообщение пустое' })
if (text.length > 2000) return reply.code(400).send({ error: 'Сообщение слишком длинное' })
const msg = await prisma.orderMessage.create({ data: { orderId: id, authorType: 'user', text } })
request.server.eventBus.emit(NOTIFICATION_EVENTS.ORDER_MESSAGE_SENT, {
orderId: id,
authorType: 'user',
messageId: msg.id,
preview: text,
})
return reply.code(201).send({ item: msg })
},
)