Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
42 replies
Børge

How would I order by the role?

Hello, I'm trying to set up an API, where I return some users. I've got it working, where it returns the right users, with their roles.
But I would like to order them so the role "ADMIN" comes first. I know there is orderBy, but every time I use it, it just sends a bunch of errors. Maybe I'm on a completely wrong track?

What I'm currently doing to get the user:
  const users = await prisma.user.findMany({
    skip: skip,
    take: perPage,
    where: {
      role: {
        some: {
          role: {
            in: ["ADMIN", "DEV"]
          }
        }
      }
    },
    include: {
      role: {
        where: {
          NOT: {
            role: 'USER'
          },
        }
      }
    }
  });
Was this page helpful?