Files
zooqueen fb4e3df0e3 rename: @hanzo/sign-* → @hanzo/esign-* (full eSign brand consistency)
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign).
Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files)
and align docker/Dockerfile turbo --scope/--filter to the actual remix
package name @hanzo/esign (was a pre-existing mismatch with -remix that
broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
2026-06-21 19:56:09 -07:00

100 lines
2.2 KiB
TypeScript

import { Prisma } from '@prisma/client';
import { AppError, AppErrorCode } from '@hanzo/esign-lib/errors/app-error';
import type { FindResultResponse } from '@hanzo/esign-lib/types/search-params';
import {
buildOrganisationWhereQuery,
getHighestOrganisationRoleInGroup,
} from '@hanzo/esign-lib/utils/organisations';
import { prisma } from '@hanzo/esign-prisma';
import {
ZFindOrganisationMembersRequestSchema,
ZFindOrganisationMembersResponseSchema,
} from './find-organisation-members.types';
type FindOrganisationMembersOptions = {
userId: number;
organisationId: string;
query?: string;
page?: number;
perPage?: number;
};
export const findOrganisationMembers = async ({
userId,
organisationId,
query,
page = 1,
perPage = 10,
}: FindOrganisationMembersOptions) => {
const organisation = await prisma.organisation.findFirst({
where: buildOrganisationWhereQuery({ organisationId, userId }),
});
if (!organisation) {
throw new AppError(AppErrorCode.NOT_FOUND);
}
const whereClause: Prisma.OrganisationMemberWhereInput = {
organisationId: organisation.id,
};
if (query) {
whereClause.user = {
OR: [
{
email: {
contains: query,
},
},
{
name: {
contains: query,
},
},
],
};
}
const [data, count] = await Promise.all([
prisma.organisationMember.findMany({
where: whereClause,
skip: Math.max(page - 1, 0) * perPage,
take: perPage,
orderBy: {
createdAt: 'desc',
},
select: {
id: true,
organisationId: true,
user: {
select: {
id: true,
email: true,
name: true,
avatarImageId: true,
},
},
organisationGroupMembers: {
select: {
group: true,
},
},
createdAt: true,
},
}),
prisma.organisationMember.count({
where: whereClause,
}),
]);
return {
data,
count,
currentPage: Math.max(page, 1),
perPage,
totalPages: Math.ceil(count / perPage),
} satisfies FindResultResponse<typeof data>;
};