Merhaba, Prisma.js ve Next.js kullanarak bir proje geliştiriyorum. Yorum, değerlendirme yapma kısmında takıldım. Kullanıcılar yaptığı yorumlarda puan veriyor. Yorumlarda verilen puanlardan genel skor elde edip Listing modelinde verileri çekerken göstermek istiyorum.

Listing modelinde score adlı bir alan oluştursam ve bunu yorum sayısına bölsem mantıklı olur mu?



Prisma Model:
model Listing {
id String @id @default(auto()) @map("_id") @db.ObjectId
slug String @unique

comments Comment[]
}


model Comment {
id                String         @id @default(auto()) @map("_id") @db.ObjectId
  user              User           @relation(fields: [userId], references: [id])
userId            String         @db.ObjectId
  comment           String
commentTitle      String
post              Listing        @relation(fields: [postId], references: [id], onDelete: Cascade)
postId            String         @db.ObjectId
  status            CommentPublish @default(DRAFT)
createdAt         DateTime       @default(now())
pros              String?
cons              String?
accommodationDate DateTime?
rating            Int
}
Bu kod blogu yorumlardaki skorlara göre filtreleme yapıyor benim istediğim ise genel skora göre filtreleme yapması.

Bu konu hakkında ücretli destek verebilecekler ulaşabilir.

const fetchSite = async (searchParams: SearchParams) => {
const where: any = {};

if (searchParams.rating) {
where.comments = {
some: {
rating: {
gte: Number(searchParams.rating),
},
},
};
}

const site = await prisma.listing.findMany({
where,
select: {
id: true,
title: true,
slug: true,
comments:true,
},
});

return { site };
};