mirror of
https://github.com/hanzoai/sign.git
synced 2026-11-02 15:28:54 +00:00
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.
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import { ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP } from '@hanzo/esign-lib/constants/organisations';
|
|
import { AppError, AppErrorCode } from '@hanzo/esign-lib/errors/app-error';
|
|
import { jobs } from '@hanzo/esign-lib/jobs/client';
|
|
import { buildOrganisationWhereQuery } from '@hanzo/esign-lib/utils/organisations';
|
|
import { prisma } from '@hanzo/esign-prisma';
|
|
|
|
import {
|
|
ZDeleteOrganisationMembersRequestSchema,
|
|
ZDeleteOrganisationMembersResponseSchema,
|
|
} from './delete-organisation-members.types';
|
|
|
|
type DeleteOrganisationMembersProps = {
|
|
userId: number;
|
|
organisationId: string;
|
|
organisationMemberIds: string[];
|
|
};
|
|
|
|
export const deleteOrganisationMembers = async ({
|
|
userId,
|
|
organisationId,
|
|
organisationMemberIds,
|
|
}: DeleteOrganisationMembersProps) => {
|
|
const organisation = await prisma.organisation.findFirst({
|
|
where: buildOrganisationWhereQuery({
|
|
organisationId,
|
|
userId,
|
|
roles: ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP['MANAGE_ORGANISATION'],
|
|
}),
|
|
include: {
|
|
members: {
|
|
select: {
|
|
id: true,
|
|
userId: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!organisation) {
|
|
throw new AppError(AppErrorCode.UNAUTHORIZED);
|
|
}
|
|
|
|
const membersToDelete = organisation.members.filter((member) =>
|
|
organisationMemberIds.includes(member.id),
|
|
);
|
|
|
|
await prisma.$transaction(async (tx) => {
|
|
await tx.organisationMember.deleteMany({
|
|
where: {
|
|
id: {
|
|
in: organisationMemberIds,
|
|
},
|
|
organisationId,
|
|
},
|
|
});
|
|
});
|
|
|
|
for (const member of membersToDelete) {
|
|
await jobs.triggerJob({
|
|
name: 'send.organisation-member-left.email',
|
|
payload: {
|
|
organisationId,
|
|
memberUserId: member.userId,
|
|
},
|
|
});
|
|
}
|
|
};
|