mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
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]>
24 lines
779 B
TypeScript
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(),
|
|
});
|