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
+13 -1
View File
@@ -1,4 +1,5 @@
import { prisma } from '../../lib/prisma.js'
import { NOTIFICATION_EVENTS } from '../../shared/constants/notification-events.js'
export async function registerAdminReviewRoutes(fastify) {
fastify.get(
@@ -43,7 +44,10 @@ export async function registerAdminReviewRoutes(fastify) {
return reply.code(400).send({ error: 'action должен быть approve или reject' })
}
const existing = await prisma.review.findUnique({ where: { id } })
const existing = await prisma.review.findUnique({
where: { id },
include: { product: { select: { title: true } }, user: { select: { name: true, email: true } } },
})
if (!existing) return reply.code(404).send({ error: 'Отзыв не найден' })
const updated = await prisma.review.update({
@@ -53,6 +57,14 @@ export async function registerAdminReviewRoutes(fastify) {
moderatedAt: new Date(),
},
})
request.server.eventBus.emit('review:created', {
rating: updated.rating,
text: updated.text || '',
productTitle: existing.product?.title || '',
userName: existing.user?.name || existing.user?.email || '',
reviewId: updated.id,
})
return { item: updated }
},
)