( input: CreatePendingInvitationInput )
| 49 | } |
| 50 | |
| 51 | export async function createPendingInvitation( |
| 52 | input: CreatePendingInvitationInput |
| 53 | ): Promise<CreatePendingInvitationResult> { |
| 54 | const invitationId = generateId() |
| 55 | const token = generateId() |
| 56 | const expiresAt = input.expiresAt ?? computeInvitationExpiry() |
| 57 | const now = new Date() |
| 58 | |
| 59 | await db.transaction(async (tx) => { |
| 60 | await tx.insert(invitation).values({ |
| 61 | id: invitationId, |
| 62 | kind: input.kind, |
| 63 | email: normalizeEmail(input.email), |
| 64 | inviterId: input.inviterId, |
| 65 | organizationId: input.organizationId, |
| 66 | membershipIntent: input.membershipIntent ?? 'internal', |
| 67 | role: input.role, |
| 68 | status: 'pending', |
| 69 | token, |
| 70 | expiresAt, |
| 71 | createdAt: now, |
| 72 | updatedAt: now, |
| 73 | }) |
| 74 | |
| 75 | for (const grant of input.grants) { |
| 76 | await tx.insert(invitationWorkspaceGrant).values({ |
| 77 | id: generateId(), |
| 78 | invitationId, |
| 79 | workspaceId: grant.workspaceId, |
| 80 | permission: grant.permission, |
| 81 | createdAt: now, |
| 82 | updatedAt: now, |
| 83 | }) |
| 84 | } |
| 85 | }) |
| 86 | |
| 87 | return { invitationId, token, expiresAt } |
| 88 | } |
| 89 | |
| 90 | async function countPendingInvitationsForOrganization(organizationId: string): Promise<number> { |
| 91 | const [row] = await db |
no test coverage detected