mirror of
https://github.com/hanzoai/sign.git
synced 2026-11-02 23:26:15 +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.
81 lines
2.0 KiB
TypeScript
81 lines
2.0 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 { sendOrganisationMemberInviteEmail } from '@hanzo/esign-lib/server-only/organisation/create-organisation-member-invites';
|
|
import { buildOrganisationWhereQuery } from '@hanzo/esign-lib/utils/organisations';
|
|
import { prisma } from '@hanzo/esign-prisma';
|
|
|
|
import {
|
|
ZResendOrganisationMemberInviteRequestSchema,
|
|
ZResendOrganisationMemberInviteResponseSchema,
|
|
} from './resend-organisation-member-invite.types';
|
|
|
|
export type ResendOrganisationMemberInvitationOptions = {
|
|
/**
|
|
* The ID of the user who is initiating this action.
|
|
*/
|
|
userId: number;
|
|
|
|
/**
|
|
* The name of the user who is initiating this action.
|
|
*/
|
|
userName: string;
|
|
|
|
/**
|
|
* The ID of the organisation.
|
|
*/
|
|
organisationId: string;
|
|
|
|
/**
|
|
* The IDs of the invitations to resend.
|
|
*/
|
|
invitationId: string;
|
|
};
|
|
|
|
/**
|
|
* Resend an email for a given member invite.
|
|
*/
|
|
export const resendOrganisationMemberInvitation = async ({
|
|
userId,
|
|
userName,
|
|
organisationId,
|
|
invitationId,
|
|
}: ResendOrganisationMemberInvitationOptions): Promise<void> => {
|
|
const organisation = await prisma.organisation.findFirst({
|
|
where: buildOrganisationWhereQuery({
|
|
organisationId,
|
|
userId,
|
|
roles: ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP['MANAGE_ORGANISATION'],
|
|
}),
|
|
include: {
|
|
organisationGlobalSettings: true,
|
|
invites: {
|
|
where: {
|
|
id: invitationId,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!organisation) {
|
|
throw new AppError('OrganisationNotFound', {
|
|
message: 'User is not a valid member of the team.',
|
|
statusCode: 404,
|
|
});
|
|
}
|
|
|
|
const invitation = organisation.invites[0];
|
|
|
|
if (!invitation) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'Invitation does not exist',
|
|
});
|
|
}
|
|
|
|
await sendOrganisationMemberInviteEmail({
|
|
email: invitation.email,
|
|
token: invitation.token,
|
|
senderName: userName,
|
|
organisation,
|
|
});
|
|
};
|