I have a waitlist where users signup with their email. Then they can use their invite code and invite more users. I am sorting users by the number of users they have invited. I am sorting like this:
const x = await prisma.user.findMany({
select: {
id: true,
email: true,
},
orderBy: {
createdUsers: {
_count: "desc",
},
},});
This is the schema:
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
email String @unique
inviteCode String @unique @default(cuid())
createdById Int?
createdBy User? @relation("UserCreatedBy", fields: [createdById], references: [id], onDelete: NoAction, onUpdate: NoAction)
createdUsers User[] @relation("UserCreatedBy")
}
What i want to do is basically tell them the position of the user in the waitlist based on the number of users they have invited. Any help will be appreciated?