@@ -46,7 +46,11 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
4646 const body : BulkInviteRequest = await request . json ( )
4747
4848 // Validate input
49- if ( ! body . invitations || ! Array . isArray ( body . invitations ) || body . invitations . length === 0 ) {
49+ if (
50+ ! body . invitations ||
51+ ! Array . isArray ( body . invitations ) ||
52+ body . invitations . length === 0
53+ ) {
5054 return NextResponse . json (
5155 { error : 'Invitations array is required and must not be empty' } ,
5256 { status : 400 }
@@ -92,7 +96,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
9296 const { organization } = permissionResult
9397
9498 // Get all emails to check for existing members and invitations
95- const emails = body . invitations . map ( inv => inv . email )
99+ const emails = body . invitations . map ( ( inv ) => inv . email )
96100
97101 // Check for existing members
98102 const existingMembers = await db
@@ -106,7 +110,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
106110 )
107111 )
108112
109- const existingMemberEmails = new Set ( existingMembers . map ( m => m . email ) )
113+ const existingMemberEmails = new Set ( existingMembers . map ( ( m ) => m . email ) )
110114
111115 // Check for existing pending invitations
112116 const existingInvitations = await db
@@ -120,7 +124,9 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
120124 )
121125 )
122126
123- const existingInvitationEmails = new Set ( existingInvitations . map ( i => i . email ) )
127+ const existingInvitationEmails = new Set (
128+ existingInvitations . map ( ( i ) => i . email )
129+ )
124130
125131 // Get inviter information
126132 const inviter = await db
@@ -143,7 +149,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
143149 results . push ( {
144150 email : invitation . email ,
145151 success : false ,
146- error : 'User is already a member of this organization'
152+ error : 'User is already a member of this organization' ,
147153 } )
148154 failed ++
149155 continue
@@ -154,7 +160,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
154160 results . push ( {
155161 email : invitation . email ,
156162 success : false ,
157- error : 'Invitation already sent to this email'
163+ error : 'Invitation already sent to this email' ,
158164 } )
159165 failed ++
160166 continue
@@ -177,6 +183,8 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
177183 } )
178184 . returning ( )
179185
186+
187+
180188 // Send invitation email
181189 const invitationUrl = `${ request . nextUrl . origin } /invites/${ token } `
182190 const emailResult = await sendOrganizationInvitationEmail ( {
@@ -196,7 +204,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
196204 results . push ( {
197205 email : invitation . email ,
198206 success : false ,
199- error : 'Failed to send invitation email'
207+ error : 'Failed to send invitation email' ,
200208 } )
201209 failed ++
202210 continue
@@ -205,20 +213,19 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
205213 results . push ( {
206214 email : invitation . email ,
207215 success : true ,
208- invitationId : inviteRecord . id
216+ invitationId : inviteRecord . id ,
209217 } )
210218 successful ++
211-
212219 } catch ( error ) {
213220 logger . error (
214221 { organizationId : orgId , email : invitation . email , error } ,
215222 'Error processing bulk invitation'
216223 )
217-
224+
218225 results . push ( {
219226 email : invitation . email ,
220227 success : false ,
221- error : 'Internal error processing invitation'
228+ error : 'Internal error processing invitation' ,
222229 } )
223230 failed ++
224231 }
@@ -242,7 +249,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
242249 total : body . invitations . length ,
243250 successful,
244251 failed,
245- }
252+ } ,
246253 }
247254
248255 return NextResponse . json ( response )
@@ -256,4 +263,4 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
256263 { status : 500 }
257264 )
258265 }
259- }
266+ }
0 commit comments