add
This commit is contained in:
parent
8652488bad
commit
29f49846b7
|
@ -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
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue