mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
58 lines
1.1 KiB
TypeScript
58 lines
1.1 KiB
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import { Prisma } from '@documenso/prisma/client';
|
|
|
|
type GetAllUsersProps = {
|
|
username: string;
|
|
email: string;
|
|
page: number;
|
|
perPage: number;
|
|
};
|
|
|
|
export const findUsers = async ({
|
|
username = '',
|
|
email = '',
|
|
page = 1,
|
|
perPage = 10,
|
|
}: GetAllUsersProps) => {
|
|
const whereClause = Prisma.validator<Prisma.UserWhereInput>()({
|
|
OR: [
|
|
{
|
|
name: {
|
|
contains: username,
|
|
mode: 'insensitive',
|
|
},
|
|
},
|
|
{
|
|
email: {
|
|
contains: email,
|
|
mode: 'insensitive',
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
const [users, count] = await Promise.all([
|
|
await prisma.user.findMany({
|
|
include: {
|
|
Subscription: true,
|
|
Document: {
|
|
select: {
|
|
id: true,
|
|
},
|
|
},
|
|
},
|
|
where: whereClause,
|
|
skip: Math.max(page - 1, 0) * perPage,
|
|
take: perPage,
|
|
}),
|
|
await prisma.user.count({
|
|
where: whereClause,
|
|
}),
|
|
]);
|
|
|
|
return {
|
|
users,
|
|
totalPages: Math.ceil(count / perPage),
|
|
};
|
|
};
|