diff --git a/apps/server/src/queue/models/post/utils.ts b/apps/server/src/queue/models/post/utils.ts index 1a352ff..98eb43c 100644 --- a/apps/server/src/queue/models/post/utils.ts +++ b/apps/server/src/queue/models/post/utils.ts @@ -1,5 +1,9 @@ import { db, VisitType } from '@nice/common'; export async function updatePostViewCount(id: string, type: VisitType) { + const post = await db.post.findFirst({ + where: { id }, + select: { id: true, meta: true }, + }); const totalViews = await db.visit.aggregate({ _sum: { views: true, @@ -16,6 +20,7 @@ export async function updatePostViewCount(id: string, type: VisitType) { }, data: { meta: { + ...((post?.meta as any) || {}), views: totalViews._sum.views || 0, }, // Use 0 if no visits exist }, @@ -28,6 +33,7 @@ export async function updatePostViewCount(id: string, type: VisitType) { }, data: { meta: { + ...((post?.meta as any) || {}), likes: totalViews._sum.views || 0, // Use 0 if no visits exist }, }, @@ -39,6 +45,7 @@ export async function updatePostViewCount(id: string, type: VisitType) { }, data: { meta: { + ...((post?.meta as any) || {}), hates: totalViews._sum.views || 0, // Use 0 if no visits exist }, },