mirror of
https://github.com/documenso/documenso
synced 2026-04-21 21:37:18 +00:00
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.
68 lines
1.3 KiB
TypeScript
68 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),
|
|
};
|
|
};
|