( client: Client, input: CreateInviteCodeInput, )
| 83 | } |
| 84 | |
| 85 | export const createInviteCode = async ( |
| 86 | client: Client, |
| 87 | input: CreateInviteCodeInput, |
| 88 | ): Promise<InviteCodeRow> => { |
| 89 | const row: InviteCodeRow = { |
| 90 | id: randomBytes(16).toString("hex"), |
| 91 | code: generateCode(), |
| 92 | role: input.role ?? "member", |
| 93 | label: input.label ?? null, |
| 94 | createdBy: input.createdBy, |
| 95 | createdAt: new Date().toISOString(), |
| 96 | expiresAt: input.expiresAt ?? null, |
| 97 | usedBy: null, |
| 98 | usedByEmail: null, |
| 99 | usedAt: null, |
| 100 | }; |
| 101 | await client.execute({ |
| 102 | sql: `INSERT INTO invite_code (id, code, role, label, created_by, created_at, expires_at) |
| 103 | VALUES (?, ?, ?, ?, ?, ?, ?)`, |
| 104 | args: [row.id, row.code, row.role, row.label, row.createdBy, row.createdAt, row.expiresAt], |
| 105 | }); |
| 106 | return row; |
| 107 | }; |
| 108 | |
| 109 | // Newest first; the admin page renders pending + used together. |
| 110 | export const listInviteCodes = async (client: Client): Promise<readonly InviteCodeRow[]> => { |
no test coverage detected