Invite several teammates at once

Node · Node · intermediate · modification

Adds the backend for the new "Invite teammates" dialog, so an admin can invite a batch of people in one go instead of one at a time. `POST /api/invites/bulk` takes the dialog's email and role columns; `buildInviteRows` in the invites service validates them, skips the rows without an email and reports a bad row by its number in the dialog, and `inviteMany` writes the result in one transaction through the existing `upsertInvite` (which now accepts a transaction client). The single invite route is untouched. `test/invites.test.js` adds unit tests for `buildInviteRows`.

Node 22, Express 4.21 (CommonJS), Prisma 5.22 on PostgreSQL 16. Existing, unchanged: `src/db.js` exports the shared `prisma` client; `src/app.js` applies `express.json({ limit: '100kb' })`, mounts `app.use('/api/invites', requireAuth, invitesRouter)`, and ends with an error handler that answers body-parser errors with their own status (400, 413) and logs anything else and answers `500 { error: 'internal' }`; `requireAuth` answers 401 without a session and otherwise sets `req.user = { id, workspaceId, role }` (positive integer ids, `role` is `member` or `admin`); `requireAdmin` in `src/middleware/auth.js` answers `403 { error: 'forbidden' }` unless `req.user.role` is `admin`. Model: `Invite { id Int @id @default(autoincrement()), workspaceId Int, email String, role String, token String @unique, invitedById Int, emailedAt DateTime?, createdAt DateTime @default(now()), @@unique([workspaceId, email]) }`. The mailer job (unchanged) emails each invite whose `emailedAt` is null; accepting an invite (unchanged) gives the account the invite's `role` in the workspace, and an `admin` can manage members, billing and invites. Two admins inviting the same new address at the same instant can hit the unique constraint, which goes to the error handler like any database error (same as the single invite). The dialog (web app) ships separately and always sends both columns with one entry per row; its role cell is a select that defaults to `member`.

Requirements

Files touched

Review this PR

Node practice