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.
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '@hanzo/esign-lib/constants/teams';
|
|
import { AppError } from '@hanzo/esign-lib/errors/app-error';
|
|
import { createTokenVerification } from '@hanzo/esign-lib/utils/token-verification';
|
|
import { prisma } from '@hanzo/esign-prisma';
|
|
|
|
import { buildTeamWhereQuery } from '../../utils/teams';
|
|
import { sendTeamEmailVerificationEmail } from './create-team-email-verification';
|
|
|
|
export type ResendTeamMemberInvitationOptions = {
|
|
userId: number;
|
|
teamId: number;
|
|
};
|
|
|
|
/**
|
|
* Resend a team email verification with a new token.
|
|
*/
|
|
export const resendTeamEmailVerification = async ({
|
|
userId,
|
|
teamId,
|
|
}: ResendTeamMemberInvitationOptions): Promise<void> => {
|
|
const team = await prisma.team.findFirst({
|
|
where: buildTeamWhereQuery({
|
|
teamId,
|
|
userId,
|
|
roles: TEAM_MEMBER_ROLE_PERMISSIONS_MAP['MANAGE_TEAM'],
|
|
}),
|
|
include: {
|
|
emailVerification: true,
|
|
},
|
|
});
|
|
|
|
if (!team) {
|
|
throw new AppError('TeamNotFound', {
|
|
message: 'User is not a member of the team.',
|
|
});
|
|
}
|
|
|
|
await prisma.$transaction(
|
|
async (tx) => {
|
|
const { emailVerification } = team;
|
|
|
|
if (!emailVerification) {
|
|
throw new AppError('VerificationNotFound', {
|
|
message: 'No team email verification exists for this team.',
|
|
});
|
|
}
|
|
|
|
const { token, expiresAt } = createTokenVerification({ hours: 1 });
|
|
|
|
await tx.teamEmailVerification.update({
|
|
where: {
|
|
teamId,
|
|
},
|
|
data: {
|
|
token,
|
|
expiresAt,
|
|
},
|
|
});
|
|
|
|
await sendTeamEmailVerificationEmail(emailVerification.email, token, team);
|
|
},
|
|
{ timeout: 30_000 },
|
|
);
|
|
};
|