feat: real user avatars in reviews, conditional product link
This commit is contained in:
@@ -40,8 +40,8 @@ export async function registerPublicReviewRoutes(fastify) {
|
||||
const rows = await prisma.review.findMany({
|
||||
where: { status: 'approved', product: { published: true } },
|
||||
include: {
|
||||
user: { select: { email: true, displayName: true } },
|
||||
product: { select: { id: true, title: true } },
|
||||
user: { select: { email: true, displayName: true, avatar: true, avatarType: true, avatarStyle: true } },
|
||||
product: { select: { id: true, title: true, published: true, slug: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take,
|
||||
@@ -54,8 +54,15 @@ export async function registerPublicReviewRoutes(fastify) {
|
||||
imageUrl: r.imageUrl,
|
||||
createdAt: r.createdAt,
|
||||
authorDisplay: publicReviewAuthorDisplay(r.user),
|
||||
productId: r.productId,
|
||||
productTitle: r.product?.title ?? '',
|
||||
authorAvatar: r.user?.avatar ?? null,
|
||||
authorAvatarType: r.user?.avatarType ?? null,
|
||||
authorAvatarStyle: r.user?.avatarStyle ?? null,
|
||||
product: {
|
||||
id: r.product?.id ?? r.productId,
|
||||
title: r.product?.title ?? '',
|
||||
published: r.product?.published ?? false,
|
||||
slug: r.product?.slug ?? '',
|
||||
},
|
||||
}))
|
||||
|
||||
return { items }
|
||||
@@ -80,7 +87,7 @@ export async function registerPublicReviewRoutes(fastify) {
|
||||
const total = await prisma.review.count({ where })
|
||||
const rawItems = await prisma.review.findMany({
|
||||
where,
|
||||
include: { user: { select: { email: true, displayName: true } } },
|
||||
include: { user: { select: { email: true, displayName: true, avatar: true, avatarType: true, avatarStyle: true } } },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
@@ -93,6 +100,9 @@ export async function registerPublicReviewRoutes(fastify) {
|
||||
imageUrl: r.imageUrl,
|
||||
createdAt: r.createdAt,
|
||||
authorDisplay: publicReviewAuthorDisplay(r.user),
|
||||
authorAvatar: r.user?.avatar ?? null,
|
||||
authorAvatarType: r.user?.avatarType ?? null,
|
||||
authorAvatarStyle: r.user?.avatarStyle ?? null,
|
||||
}))
|
||||
|
||||
return { items, total, page, pageSize }
|
||||
|
||||
Reference in New Issue
Block a user