Files
documenso/packages/lib/server-only/user/get-all-users.ts
David Nguyen 7f09ba72f4 feat: add envelopes (#2025)
This PR is handles the changes required to support envelopes. The new
envelope editor/signing page will be hidden during release.

The core changes here is to migrate the documents and templates model to
a centralized envelopes model.

Even though Documents and Templates are removed, from the user
perspective they will still exist as we remap envelopes to documents and
templates.
2025-10-14 21:56:36 +11:00

69 lines
1.3 KiB
TypeScript

import { EnvelopeType, Prisma } from '@prisma/client';
import { prisma } from '@documenso/prisma';
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([
prisma.user.findMany({
select: {
_count: {
select: {
envelopes: {
where: {
type: EnvelopeType.DOCUMENT,
},
},
},
},
id: true,
name: true,
email: true,
roles: true,
},
where: whereClause,
skip: Math.max(page - 1, 0) * perPage,
take: perPage,
}),
prisma.user.count({
where: whereClause,
}),
]);
return {
users: users.map((user) => ({
...user,
documentCount: user._count.envelopes,
})),
totalPages: Math.ceil(count / perPage),
};
};