Files
zooqueenandHanzo Dev 63fcf10df4 Resend an invitation as a fresh one from the resender
Every invitation row comes from newInvitation: its own id and token, sent
now, by the person sending it. A resend replaces the pending invitation
with a new one from the resender, so the old link stops working and the
sender who vouches for it is the one who sent it last. Only a pending
invitation is resent.

Co-authored-by: Hanzo Dev <[email protected]>
2026-10-16 06:51:56 -07:00

24 lines
779 B
TypeScript

import type { OrganisationMemberRole } from '@prisma/client';
import { nanoid } from 'nanoid';
import { generateDatabaseId } from '../../universal/id';
/**
* A new organisation invitation row: its own id and token, sent now by
* `inviterId`. Every invitation is made here, first sends and resends alike, so
* a resend is a fresh invitation from the resender rather than an old one
* re-stamped.
*/
export const newInvitation = (
invitee: { email: string; organisationId: string; organisationRole: OrganisationMemberRole },
inviterId: number,
) => ({
id: generateDatabaseId('member_invite'),
email: invitee.email,
organisationId: invitee.organisationId,
organisationRole: invitee.organisationRole,
token: nanoid(32),
inviterId,
createdAt: new Date(),
});